4

I noticed that different Android applications have different methods of selecting text. If you click-hold in Browser, there is a close up of the text plus the left and right edges can be dragged to modify the selection. In the Gmail app, a large blue circle appears below the cursor which makes it easy to move around.

The default text selection widget in an EditText box is very primitive by comparison. How can it be changed?

Update: I forgot to mention that editable is false. When editable is true the text selector is fine.

p.s. What its the proper name for the on-screen text selector?

Lawrence Barsanti
  • 31,929
  • 10
  • 46
  • 68

4 Answers4

4

As of Android 3.0 (API level 11), you can set the android:textIsSelectable attribute on any TextView to make its text selectable. The default UI as of this writing is similar to the behavior you referenced for the browser.

EDIT: Also, the default Android browser uses its own system-independent text selection mechanism that resembles the default text selection handles in Gingerbread. The "blue circle" sounds like a customized interface that a handset manufacturer added.

Roman Nurik
  • 29,665
  • 7
  • 84
  • 82
1

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

This is all just pseudo-code, and to 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;
            }
        }
    }
}
gtcompscientist
  • 671
  • 5
  • 18
1

You could use a WebView instead and enable text selection.

A. Abiri
  • 10,750
  • 4
  • 30
  • 31
1

If this is merely a problem of being unable to highlight uneditable text, you can use the XML attribute

android:textIsSelectable="true"

for that EditText box.

From the Android website:

android:textIsSelectable="true" indicates that the content of a non-editable text can be selected.

As for your question regarding terminology, I would call this the cursor.

Phil
  • 35,852
  • 23
  • 123
  • 164