2016-05-16 262 views
1

我正在使用這個偉大的庫,您可以看到here,但似乎無法設置bottomBar的bg顏色。更改BottomBar的背景顏色

我使用來設置bottomBar的代碼是這樣的:

bottomBar = BottomBar.attach(view, savedInstanceState); 
    bottomBar.setMaxFixedTabs(2); 
    bottomBar.setItemsFromMenu(R.menu.menu_bottom_bar, new OnMenuTabClickListener() { 
     @Override 
     public void onMenuTabSelected(@IdRes int menuItemId) { 
      Log.i(TAG, "onMenuTabSelected: " + menuItemId); 
     } 

     @Override 
     public void onMenuTabReSelected(@IdRes int menuItemId) { 
      Log.i(TAG, "onMenuTab- RE - Selected: " + menuItemId); 
     } 
    }); 

    bottomBar.mapColorForTab(0, R.color.colorAccentPink); 
    bottomBar.mapColorForTab(1, R.color.colorAccentPink); 
    bottomBar.mapColorForTab(2, R.color.colorAccentPink); 

我也曾嘗試設置的setBackground方法但沒有任何運氣。

我所得到的只是白色背景。

謝謝

編輯:

<?xml version="1.0" encoding="utf-8"?> 

<item 
    android:id="@+id/bb_menu_comments" 
    android:icon="@drawable/ic_comments" 
    android:title="Comments" /> 
<item 
    android:id="@+id/bb_menu_poll" 
    android:icon="@drawable/ic_poll" 
    android:title="Polls" /> 
<item 
    android:id="@+id/bb_menu_share" 
    android:icon="@drawable/ic_share" 
    android:title="Share" /> 

+0

發佈您的xml代碼以及 –

+0

@EugeneH我剛剛做了 – Mes

回答

2

你傳遞一個錯誤的參數給mapColorForTab方法。 R.color.colorAccentPink僅僅是一個資源ID,但你需要從中提取顏色是這樣的:

bottomBar.mapColorForTab(0, ContextCompat.getColor(this, R.color.colorAccentPink)); 
0
mBottomBar.getBar().setBackgroundColor(ContextCompat.getColor(this, R.color.colorAccent)); 

試試這條線。它適用於我。