[英]Change background color of ActionBarSherlock programmatically
我的表单上有一个ActionBarSherlock。 我正在运行时阅读样式信息。 其中一个样式是ActionBar的背景颜色。 如何在运行时更改此设置? 颜色可以是任何RGB值。
也许这个帮助: 如何在ActionBarSherlock中设置标题颜色? via style或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);
单程:
mSupportActionBar = getSupportActionBar();
mSupportActionBar.setBackgroundDrawable(new ColorDrawable(0xff123456));
其中0xff123456
是您所需的ARGB整数。
我刚刚在Code下面使用过
getSupportActionBar().setBackgroundDrawable(new
ColorDrawable(Color.parseColor("#00853c")));
它改变了bg的颜色。 希望能帮助到你。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.