make Android Textview or EditText selectable

痞子三分冷 提交于 2020-01-04 14:18:42

问题


I want to make EditText or Textview selectable in my android project . project is for android 4.0+ . I add this : txtView.setTextIsSelectable(true) and also : txtView.setCustomSelectionActionModeCallback(new myCallback()); to make my custom selection menu . but this error happend when i want to select the text .

W/TextView﹕ TextView does not support text selection. Action mode cancelled.

i searched about the error but didn't find the solution .what should i do ?


回答1:


<TextView
    android:id="@+id/id"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textIsSelectable="true"
    android:text="" />

*API Level 11 and up only




回答2:


setTextIsSelectable does fix the problem on Android 7.1.1 for sure. The setEnabled(false) and then true didn't work.

editText.setTextIsSelectable(true);

My exact situation was having setFocusable(false) and adding an onClickListener, then setting setFocusable(true) and onClickListener(null) gave me the error in the OP.

(not correct syntax but you get the idea)



来源:https://stackoverflow.com/questions/28605680/make-android-textview-or-edittext-selectable

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!