Is it possible to select all Edittext text when in focus?

Asked

Viewed 377 times

4

I have a EditText and when I use:

editText.requestFocus();

I’d like you to select the whole text, it’s possible?

1 answer

5


There are two ways, the first is to change the property of the EditText in the xml layout and add:

android:selectAllOnFocus="true"

The other is via script, no onCreate you set to select everything in Focus:

editText.setSelectAllOnFocus(true);

Then you can use:

editText.requestFocus();

I couldn’t perform the test, but I believe selectAll also work:

editText.selectAll();

Browser other questions tagged

You are not signed in. Login or sign up in order to post.