android - 改变背景颜色底部栏android

标签 android android-actionbar bottombar

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

这是我的代码

菜单 > tabhost_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" />

HomeActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_home);

    coordinatorLayout = (CoordinatorLayout) findViewById(R.id.tabhost_activity);

    BottomBar bottomBar = BottomBar.attach(this, savedInstanceState);
    bottomBar.setItemsFromMenu(R.menu.tabhost_bottom, new OnMenuTabSelectedListener() {
        @Override
        public void onMenuItemSelected(int itemId) {

        }
    });

    // Set the color for the active tab. Ignored on mobile when there are more than three tabs.
    bottomBar.setActiveTabColor("#55a8e5");

    // Use the dark theme. Ignored on mobile when there are more than three tabs.
    bottomBar.setBackgroundColor(Color.parseColor("#55a8e5"));
    // Use custom text appearance in tab titles.
    //bottomBar.setTextAppearance(R.style.MyTextAppearance);

    // Use custom typeface that's located at the "/src/main/assets" directory. If using with
    // custom text appearance, set the text appearance first.
    //bottomBar.setTypeFace("MyFont.ttf");
}

这是我的引用

http://androidgifts.com/build-android-material-design-bottom-navigation/

最佳答案

我终于用下面的代码(Xamarin C#)改变了它

var bottomBarBackground = FindViewById(Resource.Id.bb_bottom_bar_background_view);
bottomBarBackground.SetBackgroundResource(Resource.Drawable.tabbar_background);

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 版本不起作用:Question about background color

关于android - 改变背景颜色底部栏android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37984646/

相关文章:

android - 无法解析 : com. android.support :appcompat-v7. 27.+

android - 如何从自定义操作栏的顶部和底部删除边距

xaml - 如何更改 BottomBarPage 中的工具栏背景颜色

android - 如何在底栏导航上设置徽章?

java - Android 收不到广播

android - Fragments 与弃用的 TabActivity 在 3.0 之前的设备上

Android Sherlock Action Bar - 样式化 SearchView、Share Intent Icon、homeAsUpIndicator

android - 如何在android中突出显示操作栏项目选择

android - 错误:IllegalArgumentException:此组件上的样式要求您的应用程序主题为Theme.MaterialComponents

java - 如何在关闭android中的另一个 Activity 后关闭主要 Activity ?