【发布时间】:2020-02-27 19:15:08
【问题描述】:
我正在制作一个带有底部导航栏的 Android 应用。我知道如何为所有图标设置相同的颜色,但我想做
(我希望每个图标都有不同的颜色),尽管 Material Design 指南不允许这样做。
这是一个 Java 应用程序,一切正常。我只需要为栏中的每个图标设置不同的颜色。
菜单 .xml 文件:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/id1"
android:icon="pathtoicon1"
android:title="Text1" />
<item
android:id="@+id/id2"
android:icon="@pathtoicon2"
android:title="Text2" />
<item
android:id="@+id/id3"
android:icon="@pathtoicon3"
android:title="Text3" />
</menu>
在活动 .xml 文件中,我有这个与栏相关的代码:
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/bottom_navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
app:menu="@menu/bottom_navigation"
android:background="?android:attr/windowBackground"/>
编辑:我尝试更改图标矢量资产的颜色,但没有成功。
编辑二:我的 MainActivity.java 中有这些与 BNV 相关的行
底部导航视图底部导航视图 = findViewById(R.id.bottom_navigation); bottomNavigationView.setOnNavigationItemSelectedListener(navListener);
我尝试添加
setHasOptionsMenu(true);
到我的 FragmentName.java 并使用 @Vincent 给出的代码覆盖同一类中的公共 void onCreateOptionsMenu(Menu menu, MenuInflater inflater) 并附加
super.onCreateOptionsMenu(menu, inflater);
到它,但该函数永远不会被调用。有什么帮助吗?
【问题讨论】:
标签: android material-design bottomnavigationview