【发布时间】:2015-07-29 18:19:59
【问题描述】:
我需要更改标签指示器颜色(见下图):
即使我遵循以下官方教程:https://developer.android.com/training/basics/actionbar/styling.html#CustomTabs 我仍然无法使其工作。
应用编译版本为:compileSdkVersion 22
应用主题为:Theme.AppCompat.Light.DarkActionBar
...res/values/styles.xml(主题自定义文件)
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="@style/Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorDark</item>
<item name="android:actionBarTabBarStyle">@color/colorPrimary</item>
<item name="android:actionBarTabStyle">@style/ActionBarTabStyle.Example</item>
</style>
<!-- ActionBar tabs styles -->
<style name="ActionBarTabStyle.Example" parent="@style/Widget.AppCompat.Light.ActionBar.TabText">
<item name="android:background">@drawable/tab_indicator_ab_example</item>
</style>
<color name="colorDark">#ff9800</color>
<color name="colorPrimary">#ffc107</color>
<color name="happy">#ffeb3b</color>
<color name="normal">#fff176</color>
<color name="sad">#fff59d</color>
</resources>
...res/drawable/tab_indicator_ab_example.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Non focused states -->
<item android:drawable="@android:color/transparent" android:state_focused="false" android:state_pressed="false" android:state_selected="false" />
<item android:drawable="@drawable/tab_selected_example" android:state_focused="false" android:state_pressed="false" android:state_selected="true" />
<!-- Focused states -->
<item android:drawable="@drawable/tab_unselected_focused_example" android:state_focused="true" android:state_pressed="false" android:state_selected="false" />
<item android:drawable="@drawable/tab_selected_focused_example" android:state_focused="true" android:state_pressed="false" android:state_selected="true" />
<!-- Pressed -->
<!-- Non focused states -->
<item android:drawable="@drawable/tab_unselected_pressed_example" android:state_focused="false" android:state_pressed="true" android:state_selected="false" />
<item android:drawable="@drawable/tab_selected_pressed_example" android:state_focused="false" android:state_pressed="true" android:state_selected="true" />
<!-- Focused states -->
<item android:drawable="@drawable/tab_unselected_pressed_example" android:state_focused="true" android:state_pressed="true" android:state_selected="false" />
<item android:drawable="@drawable/tab_selected_pressed_example" android:state_focused="true" android:state_pressed="true" android:state_selected="true" />
</selector>
无法弄清楚问题出在哪里,一切编译都没有错误,代码一步一步按照官方文档进行。谢谢。
【问题讨论】: