All I want to do is to highlight text inside an EditText like this
Is there any good way for it?
All I want to do is to highlight text inside an EditText like this
Is there any good way for it?
i think here and here can help you
you need selector and aandroid:selectAllOnFocus="true"
<EditText
android:id="@+id/tvOrdinanceTitle"
android:layout_width="wrap_content"
android:cursorVisible="false"
android:layout_height="wrap_content"
android:background="@color/etxt_color" >
</EditText>
and :
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true"
android:color="#000000" /> <!-- pressed -->
<item android:state_focused="true"
android:color="#000000" /> <!-- focused -->
<item android:color="#FFFFFF" /> <!-- default -->
</selector>
You need to call the "selectAllOnFocus" method either in XML or programatically.
To do so in the XML, use the following example:
<EditText
android:id="@+id/group_name"
android:text="Group Name"
android:selectAllOnFocus="true"/>
You could also do it programmatically, reference the edit text in your code and call the selectAllOnFocus() method.
EditText edittext = ...;
edittext.setText("Group Name ");
edittext.selectAllOnFocus(); //You can also use "edittext.selectAll();"
Make sure you are using "android:text = " rather than "android:hint = ". Hint cannot use selectAllOnFocus and is not supposed to.
android:text will automatically disappear if you start typing while focused, but will stay if you click it again.