我已经被这个问题困扰好几天了。任何人都可以帮助我自定义操作栏下方显示的选项卡(导航模式为NAVIGATION_MODE_TABS
) ?
我基本上想更改选项卡的背景颜色和当前所选选项卡的下划线颜色。到目前为止,这就是我所做的,但它不起作用。我在用ActionBarSherlock
.
<style name="Theme.Styled" parent="@style/Theme.Sherlock.Light">
<item name="actionBarStyle">@style/Widget.Theme.Styled.ActionBar</item>
<item name="android:actionBarStyle">@style/Widget.Theme.Styled.ActionBar</item>
<item name="actionBarTabBarStyle">@style/customActionBarTabStyle</item>
<item name="android:actionBarTabBarStyle">@style/customActionBarTabStyle</item>
<item name="actionBarTabBarStyle">@style/customActionBarTabBarStyle</item>
<item name="android:actionBarTabBarStyle">@style/customActionBarTabBarStyle</item>
<item name="actionBarTabTextStyle">@style/customActionBarTabTextStyle</item>
<item name="android:actionBarTabTextStyle">@style/customActionBarTabTextStyle</item>
</style>
<style name="customActionBarTabStyle" parent="style/Widget.Sherlock.Light.ActionBar.TabView">
<item name="android:background">@color/red</item>
<item name="android:textSize">12dp</item>
</style>
<style name="customActionBarTabBarStyle" parent="style/Widget.Sherlock.Light.ActionBar.TabBar">
<item name="android:background">@color/red</item>
</style>
<style name="customActionBarTabTextStyle" parent="style/Widget.Sherlock.Light.ActionBar.TabText">
<item name="android:titleTextStyle">@style/Theme.Styled.ActionBar.TitleTextStyle</item>
<item name="android:textStyle">bold</item>
</style>
<style name="Widget.Theme.Styled.ActionBar" parent="Widget.Sherlock.ActionBar">
<item name="android:background">#A9E2F3</item>
<item name="background">#A9E2F3</item>
<item name="android:titleTextStyle">@style/Theme.Styled.ActionBar.TitleTextStyle</item>
</style>
<style name="Theme.Styled.ActionBar.TitleTextStyle" parent="android:style/TextAppearance.Holo.Widget.ActionBar.Title">
<item name="android:textColor">@color/red</item>
<item name="android:textStyle">bold</item>
</style>
<style name="Animations" />
我不确定您是否还需要这个,但我会将答案发布给其他人查看。你可以在后台设置这个Drawable
of the customActionBarTabStyle
作为可绘制资源:
<style name="customActionBarTabStyle" parent="style/Widget.Sherlock.Light.ActionBar.TabView">
<item name="android:background">@drawable/actionbar_tabs_selector</item>
<item name="android:textSize">12dp</item>
</style>
资源应该是一个选择器,如下所示:
<!-- This is the "@drawable/actionbar_tabs_selector" layout !-->
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:state_focused="false" android:state_selected="false" android:state_pressed="false" android:drawable="@drawable/actionbar_tab_style_nselected"/>
<item android:state_focused="false" android:state_selected="true" android:state_pressed="false" android:drawable="@drawable/actionbar_tab_style_selected"/>
<!-- Pressed state -->
<item android:state_pressed="true" android:drawable="@drawable/actionbar_tab_style_selected" />
<!-- Focused state -->
<item android:state_focused="true" android:state_selected="false" android:state_pressed="false" android:drawable="@drawable/actionbar_tab_style_nselected"/>
<item android:state_focused="true" android:state_selected="true" android:state_pressed="false" android:drawable="@drawable/actionbar_tab_style_nselected"/>
</selector>
所以这里的资源是2层列表。一种用于选项卡处于非活动状态时,一种用于选择选项卡时and积极的。因此,您可以根据所选状态设置 2 个图层列表。
单个图层列表可能如下所示:
<!-- This is the "@drawable/actionbar_tab_style_nselected" layout !-->
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Bottom Line -->
<item>
<shape android:shape="rectangle">
<solid android:color="@color/HCL_orange" />
</shape>
</item>
<!-- Tab color -->
<item android:bottom="2dip">
<shape android:shape="rectangle">
<solid android:color="@android:color/white" />
</shape>
</item>
</layer-list>
因此,第一项是底线,您可以将其定义为当前所选选项卡的下划线颜色,第二项是整个选项卡的颜色。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)