我的表单上有一个 ActionBarSherlock。我在运行时阅读样式信息。其中一个样式是 ActionBar 的背景颜色。我如何在运行时更改它?颜色可以是任意 RGB 值。
最佳答案
也许这有帮助:How to set title color in ActionBarSherlock?通过样式
或 getSupportActionBar().setBackgroundDrawable(getResources().getDrawable(R.drawable.ad_action_bar_gradient_bak));
通过编程方式
同主题
// add theme in app
<application android:theme="@style/MainTheme"></application>
// MainTheme
<style name="MainTheme" parent="Theme.Sherlock.Light.DarkActionBar">
</style>
// MainThemeGreen
<style name="MainThemeGreen" parent="Theme.Sherlock.Light.DarkActionBar">
<item name="android:actionBarStyle">@style/MainTheme.ActionBarStyle</item>
</style>
// ActionBar
<style name="MainTheme.ActionBarStyle" parent="Widget.Sherlock.Light.ActionBar">
<item name="android:background">@drawable/bg_green_actionbar</item>
<item name="android:titleTextStyle">@style/MainTheme.ActionBar.TitleTextStyle</item>
</style>
// Text style
<style name="MainTheme.ActionBar.TitleTextStyle" parent="TextAppearance.Sherlock.Widget.ActionBar.Title">
<item name="android:textColor">@color/White</item>
</style>
// bg_green_actionbar.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<shape>
<solid android:color="#ff74af3b" />
</shape>
</item>
</layer-list>
在此之后,您可以动态更改主题:setTheme(R.styles.MainThemeGreen);
关于android - 以编程方式更改 ActionBarSherlock 的背景颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10539971/