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

后端 未结 9 1833
旧时难觅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:27
    1. use theme

      @android:style/Theme.Black.NoTitleBar.Fullscreen
      

      or

      @android:style/Theme.WithActionBar
      
    2. set TextView in xml

      android:textIsSelectable="true"
      
    3. see result

    0 讨论(0)
  • 2020-11-27 03:33

    this is better:

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
    final android.content.ClipboardManager clipboardManager = (android.content.ClipboardManager) context
            .getSystemService(Context.CLIPBOARD_SERVICE);
    final android.content.ClipData clipData = android.content.ClipData
            .newPlainText("text label", "text to clip");
    clipboardManager.setPrimaryClip(clipData);
    } else {
    final android.text.ClipboardManager clipboardManager = (android.text.ClipboardManager) context
            .getSystemService(Context.CLIPBOARD_SERVICE);
    clipboardManager.setText("text to clip");
    }
    
    0 讨论(0)
  • 2020-11-27 03:37

    For an EditText, in manifest inside the activity use android:windowSoftInputMode="adjustResize"

    0 讨论(0)
提交回复
热议问题