Selector must have been used, but in changing the color of the font should be careful.
We set the font color in TextView general use
Android:textcolor= "@color/red"
But when we use selector to dynamically modify the font color, we use
[HTML]View Plaincopy
- android:color="@color/red"
I encountered this problem in the tabactivity, each tab is selected when the change to blue.
The code for Tab_item.xml is as follows:
[HTML]View Plaincopy
- <? XML version= "1.0" encoding="Utf-8"?>
- <linearlayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:id="@+id/ll_software_tabwidget_item"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- android:gravity="Center_horizontal"
- android:orientation="vertical" >
- <ImageView
- android:id="@+id/iv_software_tabwidget_icon"
- android:layout_width="30dip"
- android:layout_height="30dip"
- android:layout_marginbottom="1dip"
- android:layout_margintop="5dip"
- android:scaletype="Fitxy" />
- <TextView
- android:id="@+id/tv_software_tabwidget_text"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_marginbottom="5dip"
- android:textcolor="@drawable/software_textcolor"
- android:textsize="14dip" />
- </linearlayout>
Note android:textcolor= "@drawable/software_textcolor", that is, Software_textcolor.xml is selector, the source code is as follows:
[HTML]View Plaincopy
- <? XML version= "1.0" encoding="Utf-8"?>
- <selector xmlns:android="http://schemas.android.com/apk/res/android" >
- <item android:state_selected="true" android:color="@color/software_textcolor_selected "></Item>
- <item android:state_selected="false" android:color="@color/software_textcolor_ Unselected "></Item>
- </selector>
This file is the place to note, you must use android:color= "@color/software_textcolor_selected", you cannot use the Android:textcolor property.
Additional Color.xml source code is as follows:
[HTML]View Plaincopy
- <? XML version= "1.0" encoding="Utf-8"?>
- <resources>
- <color name="software_textcolor_selected"> #FF1C94EA</color>
- <color name="software_textcolor_unselected"> #FFDCE0DF</color>
- </Resources>
Use selector to modify the color of fonts in TextView