2013-07-17 12 views
5

どのようにスタイルを変更しても、赤い矢印が指すボックスの背景色は背景から変わりません。ActionBarのタイトルの背景色を変更するには?

img

どのように私はその色を変更できますか?私は4.0+をターゲットにしており、デバイスやOSについては気にしません。

ここにmy styles.xml fileへのリンクがあります。申し訳ありませんが、このプロジェクトはNDAの下にあるので、いくつかのことを検閲しなければなりませんでした。

私を含む多くのこと試してみました

android:actionBarItemBackground を変更actionBarWidgetStyle

  • android:backgroundを変更actionBarStyle
  • android:backgroundを変更windowTitleBackgroundStyle
  • android:backgroundを変更

    • を210

      これらの作品はありません。そのテキストビューは常に私のベーステーマのandroid:background値に固執しているようで、何もそれを無効にすることはできませんでした。

      私は何が間違っているのか、間違っていますか?

  • +0

    http://jgilfelt.github.io/android-actionbarstylegeneratorを使用して一連のリソースを生成し、まだ試していない関連性のあるものを参照してください。 – CommonsWare

    答えて

    1

    あなたのxmlファイルのinteristing部分がある:

    <!-- ActionBar --> 
        <style name="CCCWidgetActionBar" parent="@android:style/Widget.Holo.ActionBar"> 
         <item name="android:background">@color/nav_background</item> 
         <item name="android:textColor">@color/nav_text</item> 
         <item name="android:titleTextStyle">@style/CCCWidgetActionBarTitle</item> 
         <item name="android:textViewStyle">@style/CCCWidgetActionBarTitle</item> 
    
         <item name="android:windowTitleStyle">@style/CCCWindowTitle</item> 
         <item name="android:windowTitleBackgroundStyle">@style/CCCWindowTitleBackground</item> 
         <item name="android:windowBackground">@color/nav_background</item> 
        </style> 
    

    ちょうど変更:

    <item name="android:background">@color/nav_background</item> 
    

    <item name="android:background">@color/pink</item> 
    

    によって、あるいは他の任意の色。

    私にとってうまく動作します。

    +0

    私のGalaxy S IIでは動作しません。質問に記載されているのと同じ問題。 – chakrit

    +0

    タイトルテキストはアクションバーの背景を使用せず、アプリケーションの背景スタイルのみを使用します。これにより、他のすべての背景色も変更することなくその特定の色を変更することが不可能になります。 – chakrit

    +0

    私はLenovo S880でも同じ問題を抱えています。私はおそらくこれはデバイスの問題だと思うかもしれませんが、Google+アプリは同じデバイス上に素晴らしいアクションバーの色を持っています..奇妙な – Zyoo

    1

    カスタムアクションバーを作成して、タイトルバックグラウンドカラーを任意に変更することができます。

    は、この手順に従います。このため

    のみ可能タイトルのカスタムシャーロックバーを作成します。

    アプリのタイトル用に個別のxmlファイルを作成します。

    ファイルは次のように含まれている...このカスタムレイアウトで

    、我々はカラーコードを使用して背景色を変更することができます。.. MainActivityについては

    header_sherlock.xml

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="horizontal" 
    android:weightSum="3" 
    android:background="#008000" 
    > 
    
        <TextView 
        android:id="@+id/header_tvleft" 
        android:layout_width="0dp" 
        android:layout_height="fill_parent" 
        android:layout_weight="1" 
        android:gravity="left" 
        android:layout_marginTop="@dimen/margintop" 
        android:clickable="true" 
        android:paddingLeft="@dimen/layoutpaddingleft" 
        android:text="Textview" 
        android:textColor="#ffffff" 
        android:textSize="@dimen/header_leftbtn" 
        /> 
    
    
    <TextView 
        android:id="@+id/header_tvcenter" 
        android:layout_width="0dp" 
        android:layout_height="fill_parent" 
        android:layout_weight="1" 
        android:gravity="center_horizontal" 
        android:layout_marginTop="@dimen/margintop" 
        android:layout_marginRight="@dimen/sherlockpaddingright" 
        android:layout_marginLeft="@dimen/sherlockpaddingleft" 
        android:text="Textview" 
        android:textColor="#ffffff" 
        android:textStyle="bold" 
        android:textSize="@dimen/header_title" 
        /> 
    
        <TextView 
        android:id="@+id/header_tvright" 
        android:layout_width="0dp" 
        android:layout_height="fill_parent" 
        android:layout_weight="1" 
        android:gravity="right" 
        android:layout_marginTop="@dimen/margintop" 
        android:clickable="true" 
        android:paddingRight="@dimen/layoutpaddingright" 
        android:text="Textview" 
        android:textColor="#ffffff" 
        android:textSize="@dimen/header_rightbtn" 
        /> 
    
    </LinearLayout> 
    

    かどのアクティビティをタイトルに追加しますか:

      getSupportActionBar().setDisplayHomeAsUpEnabled(true); 
        getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM); 
        getSupportActionBar().setCustomView(R.layout.header_sherlock); 
        header_tvleft = (TextView) findViewById(R.id.header_tvleft); 
        header_tvleft.setText("LeftTitleName"); 
        header_tvcenter = (TextView) findViewById(R.id.header_tvcenter); 
        header_tvcenter.setText("CenterTitleName"); 
        header_tvright = (TextView) findViewById(R.id.header_tvright); 
        header_tvright.setText("RightTitleName"); 
    

    sメソッド..

    +0

    ActionBarSherlockを使わずに、Android ActionBarだけを使用してこれを行うことは可能ですか? – chakrit

    0

    これは、古い質問ですが、私はちょうど正確に同じ問題を持っていた - 私にとっての問題は、私はこれを持っていたことだった:btn_darkが定める一般的なボタンの再使用、描画可能だった

    <item name="android:actionBarItemBackground">@drawable/btn_dark</item> 
    <item name="actionBarItemBackground">@drawable/btn_dark</item> 
    

    有効、押された、および無効の状態の色です。それは新しいデバイスでうまく動作しますが、私の古い2.3の電話ではタイトルに灰色の背景がありました。

    興味深いことに、ディスエーブル状態(暗いグレーの色として設定)は、古いデバイスではアクションバーのタイトルの背景に適用されていました。無効にされた色を透明に設定することが修正されました。

    4

    さてあなたは、アンドロイドを変更する必要があります。windowBackground

    <style name="CCCBaseTheme" parent="@android:style/Theme.Holo"> 
        <item name="android:windowBackground">@color/nav_background</item> 
        <item name="android:textColor">@color/text</item> 
    
        <item name="android:actionBarStyle">@style/CCCWidgetActionBar</item> 
    
    </style> 
    

    と背景は、これが役立つことを願っています。

    +0

    うわー、2年後にハハ。質問の文脈でもうこれをテストすることができないので、これが適切な解決策であるかどうかはわかりません。他の誰かが来て、これがうまくいっていると言えば、私は受け入れられたとマークします。 – chakrit

    +0

    hehe昨日私はこの問題に直面しました。私はいつもカスタムアクションバーを使用しています。私はそれをテストしました(windowBackground)。 –

    関連する問題