【android】設定View字型點選變色和邊框背景設定
阿新 • • 發佈:2019-02-19
1.設定字型變色
selector_orange_white.xml
<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <!--黑白字型顏色切換 預設是黑 點選之後是白--> <item android:color="@color/oranger" android:state_pressed="false" android:state_enabled="true"/> <item android:color="@color/white" android:state_pressed="true" android:state_enabled="true"/> <item android:color="@color/invaild" android:state_enabled="false"/>" </selector>
2.設定背景變化
selector_highlight_button.xml
<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android" > <item android:state_pressed="false" android:drawable="@drawable/shape_button_highlight"/> <item android:state_pressed="true" android:drawable="@drawable/shape_button_highlight_clicked"/> </selector>
shape_button_hightlight.xml
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" > <stroke android:width="1dp" android:color="#ff8500" /> <solid android:color="@color/white" /> <padding android:bottom="1dp" android:left="1dp" android:right="1dp" android:top="1dp" > </padding> </shape>
shape_button_highlight_clicked.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<stroke
android:width="1dp"
android:color="#ff8500"
/>
<solid
android:color="#ffb055"
/>
<padding
android:bottom="1dp"
android:left="1dp"
android:right="1dp"
android:top="1dp"
>
</padding>
</shape>
最後的使用:
android:background="@drawable/selector_highlight_button"
android:textColor="@color/selector_orange_white"