How do I enable standard copy paste for a TextView in Android?

后端 未结 9 1873
旧时难觅i
旧时难觅i 2020-11-27 03:09

I want to enable standard copy paste for a TextView (the same as for EditText). How can I do it?

I tried using a non-editable EditText but it didn\'t work well (some

9条回答
  •  独厮守ぢ
    2020-11-27 03:13

    if someone wants to go the extra mile and do the select and copy to the clipboard with one click :

     phone.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View view) {
                                ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
                                ClipData clip = ClipData.newPlainText("PhoneNumber", phone.getText());
                                clipboard.setPrimaryClip(clip);
    
                            }
                        });
    

    phone is the TextView and phone.Text is the Text that will be copied to the clipboard.

提交回复
热议问题