android - 如何设置BottomBar的背景颜色?

标签 android bottombar

我使用this在我的应用中使用 BottomBar 库,但我无法为此 BottomBar 设置背景颜色。

我的代码:

 mBottomBar = BottomBar.attach(parent.findViewById(R.id.content), savedInstanceState);
    mBottomBar.setItemsFromMenu(R.menu.bottombar_menu, new OnMenuTabClickListener() {
        @Override
        public void onMenuTabSelected(@IdRes int menuItemId) {

        }

        @Override
        public void onMenuTabReSelected(@IdRes int menuItemId) {

        }
    });

    mBottomBar.mapColorForTab(0, ContextCompat.getColor(getActivity(), R.color.colorAccent));
    mBottomBar.mapColorForTab(1, ContextCompat.getColor(getActivity(), R.color.colorAccent));

我的 BottomBar 背景颜色是白色 - 我想将 BootomBar 设置为: enter image description here

UPD 1我尝试了以下代码:

mBottomBar.setBackgroundColor(getResources().getColor(R.color.colorAccent));

但是我的内容的背景发生了变化(在屏幕截图中查找附近的内容),但 BottomBar 中没有这种变化

最佳答案

尝试一下这个。这对我有用

mBottomBar.getBar().setBackgroundColor(ContextCompat.getColor(getActivity(), R.color.colorAccent));

关于android - 如何设置BottomBar的背景颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37562295/

相关文章:

android - Android Studio 能否用于从库项目中创建与 Unity 插件兼容的 JAR?

android - RecyclerView with LinearLayoutManager 带有不回收的标题 View

java - 如何以编程方式隐藏底部栏中的项目

android - Youtube 底栏

android - 类型推断失败。请尝试明确指定类型参数 : Kotlin

Android Espresso 2 结束通话

android - android应用程序中谷歌分析的崩溃代码

android - 超过 3 个项目的底部导航 View : tab title is hiding

ios - 如何让 UITabBar 在 iPhone X 上延伸到底部?

java - 不推荐使用 setOnNavigationItemSelectedListener