相关疑难解决方法(0)

如何从底部导航视图更改特定图标图像

我需要在我的 android 应用程序中实现底部导航视图。中间的图标需要是图像,即公司徽标。但是当我运行该应用程序时,它只出现一个灰色填充的圆形图标。上面的图片显示了我想要的和我得到的。

我想要的是: 在此处输入图片说明

我得到的: 在此处输入图片说明

我已经在这个网站上尝试过其他问题,但是每个答案都告诉我们使用可绘制对象更改 XML 中的 iconTintList,但中心图标是一个具有多种颜色的矢量。

当我尝试将 null 设置为 setIconTintList 方法时,适用于中间图标,但其他图标也会更改为原始颜色。

//This doesn't work to other icons, only for the middle one 
mBottomNav.setItemIconTintList(null);
Run Code Online (Sandbox Code Playgroud)

我还尝试获取菜单并仅为中间的设置图标色调列表,就像上面的代码一样,但也不起作用。

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
    mBottomNav.getMenu().findItem(R.id.nav_buy).setIconTintList(null);
}
Run Code Online (Sandbox Code Playgroud)

这是 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" />
Run Code Online (Sandbox Code Playgroud)

这是java实现:

mBottomNav = findViewById(R.id.bottomNavigationView);
mBottomNav.setOnNavigationItemSelectedListener(this);
Run Code Online (Sandbox Code Playgroud)

谢谢你的帮助!

android bottomnavigationview android-bottom-nav-view

5
推荐指数
1
解决办法
4381
查看次数