How to change the text selection widget on the screen?

I noticed that different Android apps have different text selection methods. If you click in the browser, the text will be closed, and the left and right edges can be dragged to change the selection. A large blue circle appears under the cursor in the Gmail app, making it easy to navigate.

The default text selection widget in the EditText field is very primitive for comparison. How can it be changed?

Refresh . I forgot to mention that the editable is false. When true is edited, the text selector is fine.

ps What is its own name for an on-screen text selector?

+4
source share
4 answers

Starting with Android 3.0 (API level 11), you can set the android:textIsSelectable on any TextView to make its text available. The default user interface in this example is similar to the behavior you specified for the browser.

EDIT . In addition, the Android browser by default uses its own system-independent text selection engine, which resembles the default text selection descriptors in Gingerbread. The Blue Circle sounds like a customizable interface added by the phone manufacturer.

+4
source

I would implement this as a custom class that extends EditText and implements LongClickListener and ClickListener . Then you can take complete control.

This is just pseudo code and point you in the right direction:

 public class PrettySelectionEditText extends EditText implements OnLongClickListener, OnClickListener { private boolean isSelecting = false; public PrettySelectionEditText(Context context) { super(context); } @Override public boolean onLongClick(View v) { if (clickIsOnText) { isSelecting = true; //Highlight word and pretty controls } //Select here based on the text they've clicked on? //Return true if you want to consume the longClick return true; } @Override public void onClick(View v) { //If in selection mode if (isSelecting) { //check where they've clicked if (clickIsInSelect) { updateSelection(click); } else { isSelecting = false; } } } } 
+1
source

Instead, you can use WebView and enable text selection.

+1
source

If this is simply a problem of being unable to select unedited text, you can use the XML attribute

 android:textIsSelectable="true" 

for this EditText .

On the Android website :

android: textIsSelectable = "true" indicates that you can select the contents of the edited text.

As for your question regarding terminology, I would call it a cursor.

+1
source

All Articles