我需要在我的Android应用程序中实现一个底部导航视图(Bottom Navigation View)。中间的图标需要是一张图片,即公司徽标。但是当我运行应用程序时,只会出现一个填充为灰色的圆形图标。上面的图片显示了我想要的效果以及我得到的结果。
我想要的:
我得到的:
我已经尝试了这个网站上的其他问题,但每个答案都告诉我使用XML中的drawable更改iconTintList,但中心图标是具有多个颜色的向量图。当我尝试将setIconTintList方法设置为null时,可以使中间的图标正常显示,但其他图标也会变回原始颜色。
这是 XML 实现:
感谢您的帮助!
我想要的:
![enter image description here](https://istack.dev59.com/LHvbI.webp)
![enter image description here](https://istack.dev59.com/HAKW0.webp)
//This doesn't work to other icons, only for the middle one
mBottomNav.setItemIconTintList(null);
我也尝试获取菜单,并为中间的那个设置图标着色列表,就像上面的代码一样,但是也不起作用。
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
mBottomNav.getMenu().findItem(R.id.nav_buy).setIconTintList(null);
}
这是 XML 实现:
<android.support.design.widget.BottomNavigationView
android:id="@+id/bottomNavigationView"
android:layout_width="match_parent"
android:layout_height="0dp"
android:background="@color/kmv_background"
app:itemIconTint="@drawable/bottom_nav_item_color"
app:itemTextColor="@drawable/bottom_nav_item_color"
app:labelVisibilityMode="labeled"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:menu="@menu/bottom_navigation" />
这是Java的实现:
mBottomNav = findViewById(R.id.bottomNavigationView);
mBottomNav.setOnNavigationItemSelectedListener(this);
感谢您的帮助!