我想更改选项卡栏的高亮颜色。我还将使用 Android 动作栏样式生成器来更改颜色,但它不会改变。
风格.xml
<resources>
<style name="Theme.Example" parent="@android:style/Theme.Holo">
<item name="android:actionBarTabStyle">@style/ActionBarTabStyle.Example</item>
</style>
<style name="ActionBarTabStyle.Example" parent="@android:style/Widget.Holo.ActionBar.TabView">
<item name="android:background">@drawable/tab_indicator_ab_example</item>
</style>
</resources>
tab_indicator_ab_example
<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="@android:color/transparent" />
<item android:state_focused="false" android:state_selected="true" android:state_pressed="false" android:drawable="@drawable/tab_selected_example" />
<!-- Focused states -->
<item android:state_focused="true" android:state_selected="false" android:state_pressed="false" android:drawable="@drawable/tab_unselected_focused_example" />
<item android:state_focused="true" android:state_selected="true" android:state_pressed="false" android:drawable="@drawable/tab_selected_focused_example" />
<!-- Pressed -->
<!-- Non focused states -->
<item android:state_focused="false" android:state_selected="false" android:state_pressed="true" android:drawable="@drawable/tab_unselected_pressed_example" />
<item android:state_focused="false" android:state_selected="true" android:state_pressed="true" android:drawable="@drawable/tab_selected_pressed_example" />
<!-- Focused states -->
<item android:state_focused="true" android:state_selected="false" android:state_pressed="true" android:drawable="@drawable/tab_unselected_pressed_example" />
<item android:state_focused="true" android:state_selected="true" android:state_pressed="true" android:drawable="@drawable/tab_selected_pressed_example" />
</selector>
请指导我更改选项卡栏的突出显示颜色
应用程序中完成了这段代码。现在您可以轻松地将此代码放入您的应用程序中,我希望这对您来说效果很好。
请将下面的文件放入您的可绘制文件夹,并将此文件设置为您的背景。
tab_bg_selector.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@color/tab_selected" android:state_pressed="true"/>
<item android:drawable="@color/tab_selected" android:state_selected="true"/>
<item android:drawable="@color/tab_normal"/>
</selector>
将此代码放在您的 res -> 值 -> 颜色.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name = "tab_normal"> #FF0000 </color>
<color name = "tab_selected"> #000000 </color>
</resources>
尝试使用 http://jgilfelt.github.io/android-actionbarstylegenerator/这是最简单的方法。
1) 使用UI为不同的项目
选择颜色 2)完成后,单击"下载.ZIP"
3)ZIP文件包含您必须在项目中复制的资源文件 res/布局和res/drawableXXXX文件夹