To change the Text color for TextView when it is Pressed or brought on Focus you need to create a selector XML file under res folder. If you do not find a color folder just create a new folder named "color"
Now Right Click on the color folder and select Android XML file
Now select Selector as Root element
res->color->textview_selector.xml<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:color="#878782"/>
<item android:state_focused="true" android:color="#483728"/>
<item android:color="#ff000000"/>
</selector>
activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<EditText
android:id="@+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:textColor="@color/textview_selector"
android:ems="10" >
<requestFocus />
</EditText>
</RelativeLayout>
Provide Feedback For This Article
We take your feedback seriously and use it to improve our content. Thank you for helping us serve you better!
😊 Thanks for your time, your feedback has been registered!
Comments & Discussion
Facing issues? Have questions? Post them here! We're happy to help!