How to make custom text selection dialogue in android

Viewed 158

How to Highlight text in android TextView like this? & also how to show a custom dialogue on text selection?

enter image description here

I Have Tried with TextView default property

android:enabled="true"
android:textIsSelectable="true"
android:focusable="true"
android:longClickable="true"

But By Using this it only show default share and copy option from android.

1 Answers

You can set the hilight by calling setSelection on the TextView. As for the dialog- you can add to it, but you can't remove from it. The way to add to it is to create an Activity with an intent filter that makes it catch the PROCESS_TEXT action. That will automatically make Android add your app to the copy paste bar with the name of your app, and allow users to click on it to perform whatever transformation you wish.

Please note that this will occur in every app, not just your own. I don't know of a way to make it specific to your app.

So for example the "Tweet" option on your bar there is because you have twitter installed. Delete it and the option would disappear. There's no other way, other than to totally turn off that menu and build your own version.

Related