无法使用 ActionBarSherlock 更改选项卡的背景

2024-03-11

我想更改选项卡的背景。在过去的两天里我尝试了一切,所以我决定在这里发布我的代码。 ActionBar 的背景设置正确,但 TABS 保持黑色。

  <style name="CustomActivityTheme" parent="Theme.Sherlock">
    <item name="android:actionBarStyle">@style/MyActionBar</item>
    <item name="android:actionBarTabStyle">@style/MyActionBarTabStyle</item>
    <!-- other activity and action bar styles here -->
</style>

<!-- style for the action bar backgrounds -->
<style name="MyActionBar" parent="Widget.Sherlock.ActionBar">
    <item name="android:background">@drawable/backgroundactionbar</item>
</style>


<style name="MyActionBarTabStyle" parent="Widget.Sherlock.ActionBar.TabView">
<item name="android:background">@drawable/backgroundactionbar</item>
</style>

清单上:

         <activity android:name=".FragmentActivityDashboard"
              android:label="@string/app_name"
              android:configChanges="keyboardHidden|orientation|screenLayout"
              android:theme="@style/CustomActivityTheme"
              > 
    </activity>

您需要声明两件事要更改。 android:actionBarStyle 和 actionBarStyle

<!-- Theme For Tabs and ActionBar Background -->
<style name="Theme.Tabs" parent="Theme.Sherlock">
    <item name="android:actionBarTabStyle">@style/ActionBarTab</item>
    <item name="actionBarTabStyle">@style/ActionBarTab</item>

    <item name="android:actionBarStyle">@style/ActionBarBlank</item>
    <item name="actionBarStyle">@style/ActionBarBlank</item>
</style>

<!-- Styles for the above theme -->
<style name="ActionBarBlank" parent="Widget.Sherlock.ActionBar">
    <item name="android:background">@drawable/tab_bg</item>
    <item name="background">@drawable/tab_bg</item>
</style>

<style name="ActionBarTab" parent="Widget.Sherlock.ActionBar.TabView">
    <item name="android:background">@drawable/bg_tab</item>
    <item name="background">@drawable/bg_tab</item>
</style>

请注意,选项卡的可绘制对象是在 xml 文件中声明的,以指示所选选项卡的单独可绘制对象。

这是 bg_tab:

<selector xmlns:android="http://schemas.android.com/apk/res/android">

<!-- Selected -->
<item android:state_selected="true" android:drawable="@drawable/tab_bg" />

<!-- Normal -->
<item android:drawable="@drawable/transparent" />

</selector>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

无法使用 ActionBarSherlock 更改选项卡的背景 的相关文章

随机推荐