AppBar 图标的正确主题属性

Proper theme attribute for AppBar icons

我的 AppBar 中有矢量图标。我如何确保它们根据主题获得正确的颜色?

我的应用程序使用 Theme.MaterialComponents.DayNight.NoActionBar 自定义 colorPrimarycolorSecondary

图标应该是这样的吗:

<vector xmlns:android="http://schemas.android.com/apk/res/android"
    android:tint="?attr/colorOnSurface">
    <path android:fillColor="#FFFFFF" android:pathData="..." />
</vector>

还是他们应该使用 colorControlNormal

<vector xmlns:android="http://schemas.android.com/apk/res/android"
    android:tint="?attr/colorControlNormal">
    <path android:fillColor="#FFFFFF" android:pathData="..." />
</vector>

colorOnPrimarySurface? (这个让它永远是白色的)

<vector xmlns:android="http://schemas.android.com/apk/res/android"
    android:tint="?attr/colorOnPrimarySurface">
    <path android:fillColor="#FFFFFF" android:pathData="..." />
</vector>

或者颜色应该在 path?

<vector xmlns:android="http://schemas.android.com/apk/res/android" >
    <path android:fillColor="?attr/colorControlNormal (colorOnSurface)" android:pathData="..." />
</vector>

或者不应该在这里设置颜色,而是直接在布局中设置颜色?

<vector xmlns:android="http://schemas.android.com/apk/res/android">
    <path android:fillColor="#FFFFFF" android:pathData="..." />
</vector>

<com.google.android.material.appbar.AppBarLayout
        android:foregroundTint="?attr/colorControlNormal" (colorOnSurface)
        android:theme="@style/ThemeOverlay.MaterialComponents.ActionBar"
        app:popupTheme="@style/ThemeOverlay.MaterialComponents.Light">

        <androidx.appcompat.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize" />

</com.google.android.material.appbar.AppBarLayout>

好的,我想我找到了答案

应该是colorControlNormal

In menu/navigation icons:

<vector
    ...
    android:tint="?attr/colorControlNormal">
    ...
</vector>

来源:https://material.io/develop/android/components/top-app-bars/#regular-top-app-bar