Is it possible to select all text in EditText when it is in focus?

2

I have a EditText and when I use:

editText.requestFocus();

I would like you to select the whole text, is it possible?

    
asked by anonymous 28.09.2017 / 19:19

1 answer

3

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

android:selectAllOnFocus="true"

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

editText.setSelectAllOnFocus(true);

Then you can use:

editText.requestFocus();

I was not able to test, but I think selectAll also works:

editText.selectAll();
    
28.09.2017 / 19:19