在main.xml中:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="#000000"
android:gravity="center_horizontal">
<EditText
android:layout_margin="8dp"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
在MyClipboardDemo.java中:
package com.li.clipboardproject;
import android.os.Bundle;
import android.app.Activity;
import android.content.Context;
import android.view.Menu;
import android.view.MenuItem;
import android.support.v4.app.NavUtils;
import android.text.ClipboardManager;
public class MyClipboardDemo extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
super.setContentView(R.layout.main);
ClipboardManager clipboardManager = (ClipboardManager)super
.getSystemService(Context.CLIPBOARD_SERVICE); //取得服务
clipboardManager.setText("学不可以已");
}
}