Android 更改底部栏的背景色

Android 更改底部栏的背景色,android,android-actionbar,bottombar,Android,Android Actionbar,Bottombar,我的Android项目有问题。 我无法更改底部栏的颜色 这就是我希望底部栏的外观: 这是我的代码 菜单>tabhost\u bottom.xml <menu xmlns:android="http://schemas.android.com/apk/res/android" > <item android:id="@+id/home_item" android:icon="@drawable/ic_home" android:color="@colo

我的Android项目有问题。 我无法更改底部栏的颜色
这就是我希望底部栏的外观:

这是我的代码

菜单>tabhost\u bottom.xml

<menu xmlns:android="http://schemas.android.com/apk/res/android"

>
<item
    android:id="@+id/home_item"
    android:icon="@drawable/ic_home"
    android:color="@color/colorPrimary"
    android:title="Home"
    />
<item
    android:id="@+id/setting_item"
    android:icon="@drawable/ic_setting"
    android:color="@color/colorPrimary"
    android:title="Setting" />
这是我的推荐信

这是第一个吗

其他选项:

似乎您需要以不同的方式设置颜色:

    // Setting colors for different tabs when there's more than three of them.
    // You can set colors for tabs in three different ways as shown below.
    mBottomBar.mapColorForTab(0, ContextCompat.getColor(this, R.color.colorAccent));
    mBottomBar.mapColorForTab(1, 0xFF5D4037);
    mBottomBar.mapColorForTab(2, "#7B1FA2");
    mBottomBar.mapColorForTab(3, "#FF5252");
    mBottomBar.mapColorForTab(4, "#FF9800");
有关更多信息:

我终于实现了用以下代码对其进行更改(Xamarin C#)

tabbar_background.axml:

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
    <item>
        <shape android:shape="rectangle">
            <solid android:color="@color/YourColor"/>
        </shape>
    </item>
</layer-list>

在这里也可以找到,尽管最终的解决方案在Xamarin版本中对我不起作用:

当您使用库(拉夫维克的底部栏)时,您可以试试这个

可以使用以下行设置特定选项卡的背景色:

bottomBar.getTabAtPosition(0).setBackgroundColor(backgroundColorInt);

当您对每个选项卡多次使用此行时,您可以更改整个选项卡的背景色。

对于所有Kotlin粉丝:要为底部导航栏中的所有项目设置背景色,只需在class MainActivity function onCreate中添加此行即可:

// finds view in bottom_nav_menu.xml
val navView: BottomNavigationView = findViewById(R.id.nav_view)
// sets background color for the whole bar 
navView.setBackgroundColor(ContextCompat.getColor(this, R.color.yourColor))

要更改选项卡的颜色吗?这是文档吗?我使用这个链接是因为您发送的链接显示教程,而不是库。这个图书馆来自谷歌。也许只是在xml中使用android:backgroundTint。
bottomBar.getTabAtPosition(0).setBackgroundColor(backgroundColorInt);
// finds view in bottom_nav_menu.xml
val navView: BottomNavigationView = findViewById(R.id.nav_view)
// sets background color for the whole bar 
navView.setBackgroundColor(ContextCompat.getColor(this, R.color.yourColor))