更改BottomBar的背景颜色
问题描述:
我正在使用这个伟大的库,您可以看到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" />
答
你传递一个错误的参数给mapColorForTab
方法。 R.color.colorAccentPink
仅仅是一个资源ID,但你需要从中提取颜色是这样的:
bottomBar.mapColorForTab(0, ContextCompat.getColor(this, R.color.colorAccentPink));
答
mBottomBar.getBar().setBackgroundColor(ContextCompat.getColor(this, R.color.colorAccent));
试试这条线。它适用于我。
发布您的xml代码以及 –
@EugeneH我刚刚做了 – Mes