5

I'm looking to create a custom menu for text selection. I know it's possible to edit the behaviour of the action bar with setCustomSelectionActionModeCallback, but in my case I don't want that action bar to show at all, I want my own floating custom menu which I have already achieved.

Only thing is that there is no way to not show the action bar menu after selecting the text in the TextView.

The behaviour I need is not the standard cut/copy/paste, the actions I have implemented are for highlighting and saving the highlighted section of text to a database.

I have done some tinkering and the best I could do was a messy reflection idea whereby I returned false in onCreateActionMode and got references to the text selection handles through reflection. It half worked and it's just as well because any form of reflection in this case is very bad practice.

My hope was that the last support library would have included the floating text menu in 6.0, and I though I could implement my own custom view in that menu, but that's wishful thinking.

If anyone has any ideas or libraries that might be of use then I'm all ears.

Conti
  • 1,017
  • 1
  • 11
  • 15

1 Answers1

2

As you already noticed, using reflection is one of the ways. I'm pretty sure that it's the only one. If you're interested in what I did with that menu, check out Carbon. Its EditText does pretty much what you need, but with reflection as well.

The code snippet is way too long to paste it here, but here are the links:

https://github.com/ZieIony/Carbon/blob/master/carbon/src/main/java/carbon/widget/EditText.java https://plus.google.com/109054799904873578131/posts/BH6r9J5gnw6

enter image description here

Basically I'm hiding the fancy Samsung's menu, disable the standard Action Mode and show my own popup window with options connected to standard copy/paste click handlers.

Zielony
  • 16,239
  • 6
  • 34
  • 39
  • This could be ideal! I just implemented Carbon and have replaced my TextViews with carbon's EditText, but it still shows the default ActionBar menu. Are there any other steps I have to take to just get your popup showing? Edit: I seen lines 188 to 222 are commented out, are they what I need for the custom menu? – Conti Oct 25 '15 at 16:12
  • The current repository code is not released yet so the maven version doesn't have the new copy/paste menu. Each vendor has their own implementation of that menu, so I need time to check all cases. The code from repo should work, but your device may be not supported yet. If you wish, use my code for your research :) – Zielony Oct 25 '15 at 16:43