在 Material 中更改处于活动和非活动状态的底部导航栏中的图标

Change icons in Material You bottom navigation bar in active and inactive states

Google 最近发布了 Material 你 (M3) for Android.

根据设计指南,如下所述:https://m3.material.io/components/navigation-bar/overview,底部导航栏的图标必须在不活动时勾勒出轮廓并在活动时填充(当有合适的图标轮廓版本时)。

但是,在实现中,我没有看到任何方法可以使图标在不活动时勾勒出轮廓并在活动时填充。

我们是否必须上传 2 个版本的相同图标,轮廓和填充,我们如何 link 我们的菜单资源文件中的这 2 个图标?

如 material 设计文档中所示,每个菜单项仅定义了 1 个图标。

即使在非活动状态下,这也会导致填充图标,如下所示。

我们如何根据图标的状态来填充和勾勒图标?这是否必须以编程方式或通过 XML 完成?

谢谢。

你必须为此制作另一个可绘制对象,你必须添加一个选定的图标和未选定的图标,就像这个一样

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/icon_selected" 
android:state_checked="true"/>
<item android:drawable="@drawable/icon_non_selected" 
android:state_checked="false"/>
</selector>

而不是在这里调用

android:icon="your drawable name"