3

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 ?

HAMED
  • 353
  • 4
  • 13
  • Check if you have android:focusable="false" or android:focusableInTouchMode="false" in your xml – karan Feb 19 '15 at 11:59
  • Have a look at this: [link](http://stackoverflow.com/questions/12346604/android-how-can-i-show-text-selection-on-textview) – denvercoder9 Feb 19 '15 at 12:00
  • What do you really want to do..select the edittext and textview text or showing a color when this widgets are selected. – Surender Kumar Feb 19 '15 at 12:00
  • @Surenderkumar i want to make it possible for users to share the text they selected in textview . – HAMED Feb 19 '15 at 12:11

2 Answers2

4
<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

shkschneider
  • 17,833
  • 13
  • 59
  • 112
sakir
  • 3,391
  • 8
  • 34
  • 50
  • 1
    Putting `textIsSelectable` on my `EditText` breaks the EditText focus, in particular when you close the keyboard (you can never open it up again). – Sebastiano Feb 19 '15 at 12:36
  • any solution can u offer @dextor ,so that I can edit my answer, – sakir Feb 19 '15 at 12:43
  • It seems like this is only related to `EditText`. So no need to change your answer. – Sebastiano Feb 19 '15 at 15:07
  • Does it really work? I tried the same. But, it's not working. Getting the following warning log while trying to select text **W/TextView: TextView does not support text selection. Action mode cancelled.** – gopalanrc Jul 07 '16 at 14:21
  • Without textIsSelectable Android is not logging "Textview does not support text selection. Action mode cancelled.". Also this doesn't solve the issue. How was this exactly helpful? – Dion Segijn Oct 05 '16 at 09:50
0

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)

John Smith
  • 3,493
  • 3
  • 25
  • 52