我一直在尝试使用 AppCompat 库自定义 Android ActionBar 选项卡上的蓝色指示器,但没有成功。我可以更改标签栏的背景颜色,但似乎 theme.xml 完全忽略了该android:actionBarTabStyle
属性。我定义了一组包含 9 个补丁的图像,一个基于状态的可绘制 XML 文件。
搜索谷歌还没有解决我的问题,我想使用尽可能少的依赖项,所以我宁愿不使用 ActionBarSherlock,除非它是最后的手段。
预期结果:标签指示器应该是橙色的,使用 9-patch 图像。
实际结果:标签指示器仍然是全息蓝色
tab_indicator.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Non focused states -->
<item android:state_focused="false" android:state_selected="false" android:state_pressed="false" android:drawable="@drawable/tab_unselected_orange" />
<item android:state_focused="false" android:state_selected="true" android:state_pressed="false" android:drawable="@drawable/tab_selected_orange" />
<!-- Focused states -->
<item android:state_focused="true" android:state_selected="false" android:state_pressed="false" android:drawable="@drawable/tab_unselected_focused_orange" />
<item android:state_focused="true" android:state_selected="true" android:state_pressed="false" android:drawable="@drawable/tab_selected_focused_orange" />
<!-- Pressed -->
<!-- Non focused states -->
<item android:state_focused="false" android:state_selected="false" android:state_pressed="true" android:drawable="@drawable/tab_unselected_pressed_orange" />
<item android:state_focused="false" android:state_selected="true" android:state_pressed="true" android:drawable="@drawable/tab_selected_pressed_orange" />
<!-- Focused states -->
<item android:state_focused="true" android:state_selected="false" android:state_pressed="true" android:drawable="@drawable/tab_unselected_pressed_orange" />
<item android:state_focused="true" android:state_selected="true" android:state_pressed="true" android:drawable="@drawable/tab_selected_pressed_orange" />
</selector>
主题.xml
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<!--
Base application theme, dependent on API level. This theme is replaced
by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
-->
<style name="AppBaseTheme" parent="style/Theme.AppCompat">
<!--
Theme customizations available in newer API levels can go in
res/values-vXX/styles.xml, while customizations related to
backward-compatibility can go here.
-->
</style>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
<item name="android:actionBarStyle">@style/ActionBarTheme</item>
<!-- Support library compatibility -->
<item name="actionBarStyle">@style/ActionBarTheme</item>
</style>
<!-- ActionBar styles -->
<style name="ActionBarTheme" parent="@style/Widget.AppCompat.ActionBar">
<item name="android:background">@color/titleBackgroundColour</item>
<item name="android:backgroundStacked">@color/tabBackground</item>
<item name="android:textColor">@color/titleTextColour</item>
<item name="android:titleTextStyle">@style/ActionBarTitleTextStyle</item>
<item name="android:actionBarTabStyle">@style/ThemeTabStyle</item>
<!-- Support library compatibility -->
<item name="actionBarTabStyle">@style/ThemeTabStyle</item>
</style>
<!-- ActionBar tabs styles -->
<style name="ThemeTabStyle" parent="@style/Widget.AppCompat.ActionBar.TabView">
<!-- tab indicator -->
<item name="android:background">@drawable/tab_indicator</item>
<!-- Support library compatibility -->
<item name="background">@drawable/tab_indicator</item>
</style>
</resources>
谁能看到这段代码有任何明显的问题,为什么它不起作用?非常感谢。