我需要更改选项卡指示器的颜色,但我没有设法做到这一点。
有谁知道该怎么办?
这是我的stiles.xml
:
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light">
<item name="android:actionBarTabTextStyle">@style/MyCustomTabView</item>
<item name="android:ratingBarStyleIndicator">@style/indicator_color</item>
<item name="android:actionBarTabStyle">@style/CustomActionBarTheme</item>
</style>
<style name="MyCustomTabView" parent="Theme.AppCompat.Light">
<item name="android:actionBarItemBackground">@style/indicator_color</item>
<item name="android:textColor">#ffffff</item>
<item name="android:textSize">12dp</item>
<item name="android:textStyle">bold</item>
<item name="android:backgroundStacked">#ffffff</item>
</style>
<style name="indicator_color">
<item name="android:background">#ffffff</item>
</style>
<style name="CustomActionBarTheme"
parent="Theme.">
<item name="android:actionBarTabStyle">@style/MyActionBarTabs</item>
</style>
<!-- ActionBar tabs styles -->
<style name="MyActionBarTabs"
parent="Theme.AppCompat.Light">
<!-- tab indicator -->
<item name="android:background">@drawable/actionbar_tab_indicator</item>
</style>
这是actionbar_tab_indicator.xml
:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- STATES WHEN BUTTON IS NOT PRESSED -->
<!-- Non focused states -->
<item android:state_focused="false" android:state_selected="false"
android:state_pressed="false"
android:drawable="@drawable/abc_ab_bottom_solid_light_holo" />
<item android:state_focused="false" android:state_selected="true"
android:state_pressed="false"
android:drawable="@drawable/abc_ab_bottom_solid_light_holo" />
<!-- Focused states (such as when focused with a d-pad or mouse hover) -->
<item android:state_focused="true" android:state_selected="false"
android:state_pressed="false"
android:drawable="@drawable/abc_ab_bottom_solid_light_holo" />
<item android:state_focused="true" android:state_selected="true"
android:state_pressed="false"
android:drawable="@drawable/abc_ab_bottom_solid_light_holo" />
<!-- STATES WHEN BUTTON IS PRESSED -->
<!-- Non focused states -->
<item android:state_focused="false" android:state_selected="false"
android:state_pressed="true"
android:drawable="@drawable/abc_ab_bottom_solid_light_holo" />
<item android:state_focused="false" android:state_selected="true"
android:state_pressed="true"
android:drawable="@drawable/abc_ab_bottom_solid_light_holo" />
<!-- Focused states (such as when focused with a d-pad or mouse hover) -->
<item android:state_focused="true" android:state_selected="false"
android:state_pressed="true"
android:drawable="@drawable/abc_ab_bottom_solid_light_holo" />
<item android:state_focused="true" android:state_selected="true"
android:state_pressed="true"
android:drawable="@drawable/abc_ab_bottom_solid_light_holo" />
</selector>
提前致谢。
答案 0 :(得分:1)
要更改用于导航选项卡的指示器,请创建一个覆盖actionBarTabStyle
属性的活动主题。此属性指向另一个样式资源,您可以在其中覆盖应指定状态列表drawable的背景属性。
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- the theme applied to the application or activity -->
<style name="CustomActionBarTheme"
parent="@style/Theme.Holo">
<item name="android:actionBarTabStyle">@style/MyActionBarTabs</item>
</style>
<!-- ActionBar tabs styles -->
<style name="MyActionBarTabs"
parent="@style/Widget.Holo.ActionBar.TabView">
<!-- tab indicator -->
<item name="android:background">@drawable/actionbar_tab_indicator</item>
</style>
</resources>
了解更多here。
答案 1 :(得分:0)
你可以改变TabWidget
的背景(这可能就是你所说的):
如果这是你的风格:
<style name="indicator_color">
<item name="android:background">@android:color/black</item>
</style>
像这样使用:
<TabWidget
style="@style/indicator_color"
android:id="@android:id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
</TabWidget>
另请注意#ffffff
为白色。所以你可能看不到效果。