Do you want to change color of text when click the textview .It is simple to get it.
First, Create change_color.xml file in drawable folder.
res/drawable/change_color.xml
First, Create change_color.xml file in drawable folder.
res/drawable/change_color.xml
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_selected="true" android:color="@color/black" />
<item android:state_focused="true" android:color="@color/black" />
<item android:state_pressed="true" android:color="@color/black" />
<item android:color="@color/white" />
</selector>
Here Color also mention so Color values are in :
res/values/color.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="white">#ffffff</color>
<color name="green">#71AB35</color>
<color name="black">#000000</color>
</resources>
Finally, you call in Activity Class, Like this:
TextView tv_test= (TextView)findViewById(R.id.text1);Happy Coding! You Enjoy it!
XmlResourceParser parser = getResources().getXml(
R.color.change_color);
ColorStateList colors = ColorStateList.createFromXml(
getResources(), parser);
tv_test.setText("PrAndroid");
tv_test.setTextColor(colors);
0 comments
Posts a comment