2017-08-17 12 views
0

を与えるものではありません私はこのコードを、プログラム的に私の「アプリケーションバーのレイアウト」でアクションバーの色を変更しようとしています:変更「アクションバー」の色が正しい色に

toolbar.setBackgroundColor(R.color.hidden_bars); //#464445 

が、私は別の色で終わるたびに、ここcolorPrimaryの暗いバージョン(#48bee6)

は私のxmlです:

<android.support.design.widget.AppBarLayout 
    android:id="@+id/id_appbar" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"> 

    <android.support.v7.widget.Toolbar 
     android:id="@+id/toolbar" 
     android:layout_width="match_parent" 
     android:layout_height="?attr/actionBarSize" 
     android:background="?attr/colorPrimary" 
     app:popupTheme="@style/ThemeOverlay.AppCompat.Light" 
     app:layout_scrollFlags="enterAlwaysCollapsed" /> 

    <android.support.design.widget.TabLayout 
     android:id="@+id/tabLayout" 
     style="@style/WenoTabLayout" 
     android:layout_width="match_parent" 
     android:layout_height="@dimen/tab_bar_height" 
     android:layout_marginTop="1dp" 
     android:background="@color/white" 
     app:tabGravity="fill" 
     app:tabMode="fixed" /> 

</android.support.design.widget.AppBarLayout> 
+0

check colorプライマリとcolorPrimaryDarkのstyle.xmlにあります。 – Reena

答えて

1

これはsetBackgroundColor(int)の一般的な誤解です。 setBackgroundColorに渡されるint値は、カラーリソースIDの代わりにカラーコードにする必要があります。最初にidでカラーコードを取得する必要があります。

// Use this instead of context if you are in activity 
int color = ContextCompat.getColor(context, R.color.your_color); 
toolbar.setBackgroundColor(color); 
+0

本当にありがとうございました – Abuzaid

関連する問題