<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:id="@+id/llMain"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="400dp"
android:layout_height="300dp"
android:orientation="vertical"
android:background="@color/colorAccent"
android:gravity="center">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter here"/>
</LinearLayout>
答案 0 :(得分:0)
我相信您正在寻找以编程方式粘贴的内容。
ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
String pasteData = "";
// If it does contain data, decide if you can handle the data.
if (!(clipboard.hasPrimaryClip())) {
} else if (!(clipboard.getPrimaryClipDescription().hasMimeType(MIMETYPE_TEXT_PLAIN))) {
// since the clipboard has data but it is not plain text
} else {
//since the clipboard contains plain text.
ClipData.Item item = clipboard.getPrimaryClip().getItemAt(0);
// Gets the clipboard as text.
pasteData = item.getText().toString();
}