6

フォームに ActionBarSherlock があります。実行時にスタイル情報を読んでいます。スタイルの要素の 1 つは、ActionBar の背景色です。実行時にこれを変更するにはどうすればよいですか? 色は、任意の RGB 値にすることができます。

4

3 に答える 3

8

たぶん、このヘルプ: 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);

于 2012-05-17T10:14:32.063 に答える
6

一方通行:

mSupportActionBar = getSupportActionBar();
mSupportActionBar.setBackgroundDrawable(new ColorDrawable(0xff123456));

0xff123456必要な ARGB 整数はどこにありますか。

于 2012-07-09T23:01:11.850 に答える