The usual thing to do in a regular project is to change the background color of the button, the text verification, and the text box.
We know that it is easy and simple to use XML to make a selection. The XML code is as follows: This can be written directly in the res/color/button_text.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=" #1c5e79 "/> <!--pressed-- <item android:state_focused= "true" android:color= "#1c5e79"/> <!--focused-- <item Android:color= "#0b5979"/> <!--default--></selector>
Just add one line of code in the XML: android:textcolor= "@drawable/tv_traffic_textcolor_selector"
But how do you use this XML in dynamic code?
The main thing to say today is that if you implement this effect through code, the implementation can be done in two ways:
First Kind
Colorstatelist csl= (colorstatelist) getresources (). Getcolorstatelist (r.drawable.tv_traffic_textcolor_selector); if (csl!=null) { holder.tvTrafficTool.setTextColor (CSL);}
The second type:
Xmlresourceparser Xpp=resources.getsystem (). GETXML (R.color.button_text); try { colorstatelist csl= colorstatelist.createfromxml (getresources (), xpp); Btn.settextcolor (CSL);} catch (Exception e) { //Todo:handle Exception}
Are the same effect. ,
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Colorstatelist Change button, text box text color