2017-05-17 21 views
0

特定のアクティビティで自分のアクションバーの背景(およびタイトル)をカスタマイズできますか?私は行っている、それが働いていない:Android - アクションバーのカスタムスタイル

<style name="AppTheme.BenchTheme"> <!-- style of my activity --> 
    <item name="android:windowBackground">@android:color/holo_blue_light</item> 
    <item name="android:actionBarStyle">@style/BenchActionBar</item> 
</style> 

<style name="BenchActionBar"> 
    <item name="android:background">@color/colorBench</item> 
</style> 

私は私のstyle.xmlでそれをやってみたいです。出来ますか?

:まず、あなたのテーマはTheme.AppCompat.Light.NoActionBarから延びる作る

おかげ

答えて

0

...;私は(。getSupportActionBar()のようなものを使用してsetBackgroundDrawable(myColor))コード経由でそれを行うことができます知っています
<style name="AppTheme.BenchTheme" parent="Theme.AppCompat.Light.NoActionBar"> 

は、その後、あなたのレイアウトで、あなたはすでにあなたが例えば好きなツールバーを追加することができます

<?xml version="1.0" encoding="utf-8"?> 
    <android.support.v7.widget.Toolbar 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     android:id="@+id/toolbar" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="@color/kelly_green" 
     android:fitsSystemWindows="true" 
     android:minHeight="?attr/actionBarSize" 
     style="@style/MyToolbarElevation" 
     > 

    <android.support.v7.widget.AppCompatTextView 
       android:id="@+id/txt_toolbar" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_marginRight="@dimen/_2sdp" 
       android:gravity="center" 
       android:textColor="#ffffff" 
       android:textSize="@dimen/_13sdp" 
       /> 
    </android.support.v7.widget.Toolbar> 
+0

ソリューションだとそれが動作します。どうも。私のソリューションがなぜ機能していないのか説明できますか?タグが壊れていますか? – Massimo

関連する問題