4

I want to do long press and select some text, I can see it in many apps, but I have no ideas for this. I am looking for some ideas or some examples? the following picture is my goal.

What I want

jiabao
  • 105
  • 1
  • 10
  • I don't think its possible, as long pressing the text will open the default android context menu and we cannot change that. However you can change it in a custom rom. – Shank Jan 31 '17 at 01:20
  • @Shank I don't think that Adobe or any E-book reader is requiring a custom ROM. Don't you think? – Anis LOUNIS aka AnixPasBesoin Jan 31 '17 at 01:39
  • @AnixPasBesoin yes you are right, i never noticed them having it – Shank Jan 31 '17 at 04:59
  • for TextView I only need android:textIsSelectable="true", But I don't want to do it on TextView, I want to do on SurfaceView, so I need to know the details. – jiabao Feb 06 '17 at 06:01

2 Answers2

6

Not sure about what you are looking for.

  • If you're just willing to make your textView selectable, make sure it looks like this:

     <TextView
     ...
     android:textIsSelectable="true"/>
    

    Which is already answered here.

  • But if what you are looking for is a Custom Text Selection Action, fortunately for you, Ian Lake has A GREAT TUTORIAL about doing just that.

    If you're into libraries, you can check this one on Github.

    You might be looking as well for some related questions. If so, check this one here on SO.

  • thank you for you help, I will look at you answer links. actually I want do it on SurfaceView, but I only want to know the UI design. – jiabao Feb 06 '17 at 06:00
  • For TextView, I have found some ideas. Now I do it on SurfaceView. so I can't use Spannable to set the selected texts, I use popupWindow to do this, But PopupWindow is expensive. can you give me some ideas? – jiabao Feb 21 '17 at 05:43
1

In your xml file and under the desired TextView, add the following attribute:

<TextView
    ...
    android:textIsSelectable="true"/>
Thorvald
  • 3,424
  • 6
  • 40
  • 66