Is it possible to create a custom floating text selection menu in Android versions prior to Marshmallow?

I am looking to create a custom menu for selecting text. I know that you can edit the behavior of the action bar using setCustomSelectionActionModeCallback, but in my case I do not want this action bar to be displayed at all, I want my own floating user menu to be reached.

The only thing is that it is not possible to display the action bar menu after selecting text in a TextView.

The behavior I need is not a standard abbreviation / copy / paste, the actions that I implemented are designed to highlight and save the selected part of the text in the database.

I did a bit of work, and the best I could do was the idea of ​​random thinking, as a result of which I returned false in onCreateActionMode and got links to select text using reflection. That half worked, and it's just as good, because any form of reflection in this case is a very bad practice.

My hope was that the last support library would include a floating text menu in 6.0, and although I could implement my own custom view in this menu, it is wishful thinking.

If anyone has ideas or libraries that might be useful, I'm all ears.

+4
source share
1 answer

As you have already noticed, using reflection is one way. I am pretty sure this is the only one. If you're interested in what I did with this menu, check out Carbon. Its EditText does pretty much what you need, but also with reflection.

The code snippet is too long to be inserted 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 hide the Samsung fashion menu, turn off the standard action mode and show my own pop-up window with options related to the standard click / folder handlers.

+2
source

Source: https://habr.com/ru/post/1242011/


All Articles