selector想必你們都用過了,可是在修改字體的顏色的時候仍是要細心。android
咱們在TextView中設置字體顏色通常使用 ide
Android:textColor="@color/red"字體
可是咱們在使用selector動態修改字體顏色的時候要使用spa
android:textColor="@drawable/selector_color_order_main_color".net
這個是修改TextView字體顏色的3d
selector_color_order_main_color.xmlorm
<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android" > <item android:state_pressed="true" android:color="@color/white"></item> <item android:state_pressed="false" android:color="@color/main_color"></item> </selector
這個是修改TextView背景顏色的xml
<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@drawable/shape_radius_order_main_color_down" android:state_pressed="true" android:color="@color/white"/> <item android:drawable="@drawable/shape_radius_order_main_color" android:state_pressed="false" android:color="@color/main_color"/> </selector>
shape_radius_order_main_color.xml <?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" > <solid android:color="@color/white" /> <stroke android:color="@color/main_color" android:width="0.5dp"/> <corners android:bottomLeftRadius="3dp" android:bottomRightRadius="3dp" android:topLeftRadius="3dp" android:topRightRadius="3dp" /> </shape>
shape_radius_order_main_color_down.xml
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" > <solid android:color="@color/main_color" /> <stroke android:width="0.5dp" android:color="@color/color_f7f7f7" /> <corners android:bottomLeftRadius="3dp" android:bottomRightRadius="3dp" android:topLeftRadius="3dp" android:topRightRadius="3dp" /> </shape>
這裏要注意的是,若是要修改TextView點擊效果的字體顏色屬性要用utf-8
android:textColor="@drawable/selector_color_order_main_color"//drawable而不能用color屬性get
android:background是改變背景顏色的
android:textColor是改變字體顏色的,固然通常默認用color一種顏色