1.在res/color文件夹下,新创selector文件。
2.添加item,书写的时候要注意是android:color,而不是android:drawable。如果该处写成drawable在4.0系统会报错“android.view.InflateException: Binary XML file line #2: Error inflating class ”。然后在添加state即可。
3.代码如下,
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="@color/white" android:state_selected="true" />
<item android:color="@color/blue" android:state_selected="false" />
<item android:color="@color/blue" />
</selector>