Is it possible to add some item in the context men

2019-04-07 15:46发布

问题:

When I enter some text and press and hold on it then context menu is presented with items like cut,copy,select text and so on.

Is there any way to add my own custom item to this context menu ? I do not how this things works but I guess that should be possible to register something in the manifest just like registering activities and broadcasts . . .

Thanks,

Any ideas are wellcomed

回答1:

Is there any way to add my own custom item to this context menu ?

Only for widgets in your own activities, not for the system as a whole.

Also, EditText is problematic even for your own activities, as some device manufacturers are bypassing the normal context menu system, so you can't add to them.

That being said, for your own activities, just follow the instructions to create a context menu for the widgets of interest.



回答2:

Have you tried putting an onLongClickListener on your EditText? This won't let you add to the current list, but you can make your own dialog show up and then add all the options above, or some of them, or none of them and your own.

I'm not sure if exactly what you're asking for is possible, and if it is my way is a little bit more work, but you'll have full control.