//徹底能夠跨進程 跨activity進行粘貼 public class MainActivity extends Activity implements OnClickListener {android
private EditText editText; private ClipboardManager mMnamager; private ClipData newPlainText; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); editText = (EditText) findViewById(R.id.editText1); findViewById(R.id.button1).setOnClickListener(this); findViewById(R.id.button2).setOnClickListener(this); mMnamager = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE); } @SuppressLint("NewApi") @Override public void onClick(View v) { switch (v.getId()) { case R.id.button1://複製文本 newPlainText = ClipData.newPlainText("simple_text", editText.getText().toString()); mMnamager.setPrimaryClip(newPlainText); break; case R.id.button2://粘粘 if(mMnamager.hasPrimaryClip()){ ClipData clip = mMnamager.getPrimaryClip(); CharSequence coerceToText = clip.getItemAt(0).coerceToText(getApplicationContext()); editText.setText(coerceToText); } break; } }
}ide
還有一種方法 其實直接調用android內置的就行 在TextView中加上 android:textIsSelectable="true" 可是這一句有時候在listview中害人呢this