Eri*_*c C 6 android android-widget android-actionbar
我的表单上有一个ActionBarSherlock.我正在运行时阅读样式信息.其中一个样式是ActionBar的背景颜色.如何在运行时更改此设置?颜色可以是任何RGB值.
也许这个帮助:如何在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>
Run Code Online (Sandbox Code Playgroud)
在此之后你可以在飞行中改变主题:setTheme(R.styles.MainThemeGreen);
单程:
mSupportActionBar = getSupportActionBar();
mSupportActionBar.setBackgroundDrawable(new ColorDrawable(0xff123456));
Run Code Online (Sandbox Code Playgroud)
0xff123456你需要的ARGB整数在哪里.
小智 5
我刚刚在Code下面使用过
getSupportActionBar().setBackgroundDrawable(new
ColorDrawable(Color.parseColor("#00853c")));
Run Code Online (Sandbox Code Playgroud)
它改变了bg的颜色.希望能帮助到你.
| 归档时间: |
|
| 查看次数: |
8619 次 |
| 最近记录: |