显示填充颜色的底部导航菜单项。我想显示我在可绘制文件夹中添加的确切图标

Bottom navigation menu items showing filled color. I want to display the exact icons that I added in the drawable folder

我在代码部分所做的方式。 动态生成的菜单代码。

 for(int i = 0;i<menuDetails.size();i++){
        int res_id = this.getResources().getIdentifier("@drawable/"+menuDetails.get(i).getMenu_icon(), null, this.getPackageName());
        navigation.getMenu()
                .add(Menu.NONE, i, Menu.NONE, menuDetails.get(i).getTitle())
                .setIcon(res_id).setChecked(false)
                .setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
    }

XML 文件:

  <FrameLayout
        android:id="@+id/home_footer"
        android:layout_width="match_parent"
        android:layout_height="@dimen/bottom_nav_height"
        android:layout_alignParentBottom="true">
        <android.support.design.widget.BottomNavigationView
            android:id="@+id/navigation"
            android:layout_width="match_parent"
            android:layout_height="@dimen/bottom_nav_height"
            android:theme="@style/Widget.BottomNavigationView"
            app:elevation="5dp"
            app:itemIconTint="@drawable/nav_selection"
            app:itemTextColor="@color/welcome_text_color"
            app:labelVisibilityMode="labeled"
            app:layout_constraintBottom_toBottomOf="parent" />
        <!--   app:itemIconTint="@drawable/nav_selection" -->
    </FrameLayout>

nav_selection 可绘制文件:

<selector
xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true" android:drawable="@drawable/ic_call"/>
<item android:state_checked="false" android:drawable="@drawable/nav_case" />

输出(实际上主页按钮是另一种适合中心的布局,我需要导航视图中的主页按钮之类的图标)。

尝试删除线下

app:itemTextColor="@color/welcome_text_color"

BottomNavigationViewapp:itemIconTint需要一个ColorStateList.

每个项目都必须定义一个 android:color 属性,它可以是 HTML 样式的十六进制颜色、对颜色资源的引用,或者 - - 在 API 23 及更高版本中 -- 解析为颜色的主题属性。

相反,您尝试使用 StateListDrawable 但它不起作用。

避免着色和使用原始图标的唯一解决方法是使用(XML 中的 app:itemIconTint="@null" 不起作用)

bottomNavigationView.setItemIconTintList(null);

无论如何我建议不要使用它。