我使用了astuetz库并为我的android应用程序实现了PagerSlidingTabStrip,它正在查找。现在我想改变按压效果,我试过了:
android:background="@drawable/tab_selecor"
标签选择器的代码:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@color/darkGreen" android:state_focused="true" android:state_pressed="true" />
<item android:drawable="@color/darkGreen" android:state_focused="false" android:state_pressed="true" />
<item android:drawable="@color/green" />
</selector>
按下的颜色应该改为深绿色,但是当你看到它没有变化时,即使我使用其他颜色,如红色,黄色......,它仍然看起来像这样。
答案 0 :(得分:3)
使用setIndicatorColor()设置指示器的颜色,setIndicatorHeight()设置高度
并使用setTabBackground()方法将背景设置为选项卡
将此drawable用于标签背景
<?xml version="1.0" encoding="utf-8"?>
<selector
xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Active tab -->
<item
android:state_selected="true"
android:state_focused="false"
android:state_pressed="false"
android:drawable="@color/red" /> <!-- Inactive tab -->
<item
android:state_selected="false"
android:state_focused="false"
android:state_pressed="false"
android:drawable="@android:color/black" />
<!-- Pressed tab -->
<item
android:state_pressed="true"
android:drawable="@android:color/transparent" />
<!-- Selected tab (using d-pad) -->
<item
android:state_focused="true"
android:state_selected="true"
android:state_pressed="false"
android:drawable="@android:color/transparent" />
</selector>