在Android的Sherlocks库中更改ActionBar中选项卡的背景色?
我正在使用Sherlock库开发Actionbar。我想以不同的方式更改Actionbar和选项卡的背景图像。目前,我已在运行时通过代码成功更改了Actionbar的背景:在Android的Sherlocks库中更改ActionBar中选项卡的背景色?,android,tabs,actionbarsherlock,Android,Tabs,Actionbarsherlock,我正在使用Sherlock库开发Actionbar。我想以不同的方式更改Actionbar和选项卡的背景图像。目前,我已在运行时通过代码成功更改了Actionbar的背景: Drawable myIcon = getResources().getDrawable(R.drawable.blue_menu_background); mActionBar.setBackgroundDrawable(myIcon); 但是我在标签背景上遇到了问题。如何更改选项卡的背景。请建议我。您可以使用标签样式,
Drawable myIcon = getResources().getDrawable(R.drawable.blue_menu_background);
mActionBar.setBackgroundDrawable(myIcon);
但是我在标签背景上遇到了问题。如何更改选项卡的背景。请建议我。您可以使用标签样式,而不是这样做:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- the theme applied to the application or activity -->
<style name="CustomActivityTheme" parent="@android:style/Theme.Holo">
<item name="android:actionBarTabTextStyle">@style/CustomTabTextStyle</item>
<item name="android:actionBarDivider">@drawable/ab_divider</item>
<item name="android:actionBarItemBackground">@drawable/ab_item_background</item>
</style>
<!-- style for the action bar tab text -->
<style name="CustomTabTextStyle" parent="@android:style/TextAppearance.Holo">
<item name="android:textColor">#2456c2</item>
</style>
</resources>
查看此项了解更多详细信息。您可以使用以下代码:
actionBar.setStackedBackgroundDrawable(new ColorDrawable(yourColor)); // for example new ColorDrawable(Color.BLUE)
要更改Actionbar选项卡的颜色,请使用以下代码:
actionBar.setStackedBackgroundDrawable(new ColorDrawable(yourColor)); // for example new ColorDrawable(Color.BLUE)
//例如,如果您想要白色作为选项卡背景,则
getActionBar().setStackedBackgroundDrawable(new ColorDrawable(Color.parseColor("#FFFFFF")));
这不会改变每个选项卡的颜色。为什么需要重新发布答案?