在res目录下新建color文件夹,在color下新建tab_item_color.xml文件,代码如下:
<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_checked="true" android:color="#f0f"/> <item android:state_pressed="true" android:color="#00f"/> <item android:state_focused="true" android:color="#f00"/> <item android:color="#000"/> </selector>在引用的地方添加background属性:
android:background="@color/tab_item_color.xml"