简体   繁体   English

AppBar 图标的正确主题属性

[英]Proper theme attribute for AppBar icons

I have vector icons in my AppBar .我的AppBar中有矢量图标。 How do I ensure they get the correct color depending on the theme?我如何确保它们根据主题获得正确的颜色?

My application uses Theme.MaterialComponents.DayNight.NoActionBar with custom colorPrimary and colorSecondary .我的应用程序使用Theme.MaterialComponents.DayNight.NoActionBar和自定义colorPrimarycolorSecondary

Should the icons look like so:图标应该是这样的:

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

or should they use colorControlNormal ?或者他们应该使用colorControlNormal吗?

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

or colorOnPrimarySurface ?colorOnPrimarySurface (This one makes it always white) (这个让它总是白色的)

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

or should the color be in the path ?还是颜色应该在path中?

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

or should the color not be set here, but straight in the layout?还是不应该在这里设置颜色,而是直接在布局中设置?

<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>

Ok, I think I found the answer好的,我想我找到了答案

It should be colorControlNormal它应该是colorControlNormal

In menu/navigation icons:在菜单/导航图标中:

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM