如何从应用程序主题更改操作模式中的膨胀工具栏项目图标颜色

问题描述 投票:0回答:1

这是我们所有应用程序使用的主题:

<resources>
    <!-- Learn more about theming: https://m2.material.io/design/material-theming/implementing-your-theme.html#color -->
    <!-- Base application theme -->
    <style name="BaseTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
        <!-- Custom toolbar style -->
        <item name="toolbarStyle">@style/CustomToolbar</item>
        <!-- Background color for application windows -->
        <item name="android:windowBackground">@color/grey_200</item>
        <!-- Default text color throughout the app -->
        <item name="android:textColor">@color/default_text</item>
        <!-- Color for text/icons over the background -->
        <item name="colorOnBackground">@color/default_text</item>

        <!-- Primary branding color for the app -->
        <item name="colorPrimary">@color/primary</item>
        <!-- Dark variant of the primary color for depth/elevation -->
        <item name="colorPrimaryDark">?colorPrimary</item>
        <!-- Primary color variant for differentiation -->
        <item name="colorPrimaryVariant">?colorPrimary</item>
        <!-- Text/icon color on primary surfaces -->
        <item name="colorOnPrimary">@android:color/white</item>

        <!-- Color used to indicate errors in components -->
        <item name="colorError">@color/red_500</item>
        <!-- Text/icon color on error surfaces -->
        <item name="colorOnError">@android:color/white</item>

        <!-- Accent color for highlighting interactive elements -->
        <item name="colorSecondary">@color/secondary</item>
        <!-- Variant of the secondary color for differentiation -->
        <item name="colorSecondaryVariant">?colorSecondary</item>
        <!-- Text/icon color on secondary surfaces -->
        <item name="colorOnSecondary">@android:color/white</item>

        <!-- Color for component surfaces like cards/menus -->
        <item name="colorSurface">@android:color/white</item>
        <!-- Text/icon color on surface elements -->
        <item name="colorOnSurface">@color/default_text</item>

        <!-- Enable activity transition animations -->
        <item name="android:windowActivityTransitions">true</item>
        <!-- Transition animation for entering activities -->
        <item name="android:windowEnterTransition">@android:transition/slide_right</item>
        <!-- Transition animation for exiting activities -->
        <item name="android:windowExitTransition">@android:transition/slide_left</item>
        <!-- Overlay for the action mode bar -->
        <item name="windowActionModeOverlay">true</item>
    </style>

    <!-- Custom toolbar styling -->
    <style name="CustomToolbar" parent="Widget.MaterialComponents.Toolbar">
        <!-- Toolbar background color -->
        <item name="android:background">?colorPrimary</item>
        <!-- Theme overlay for toolbar icons -->
        <item name="materialThemeOverlay">@style/CustomToolbarThemeOverlay</item>
        <!-- Theme for toolbar pop-up elements -->
        <item name="popupTheme">@style/CustomPopupTheme</item>
    </style>

    <!-- Theme overlay for toolbar -->
    <style name="CustomToolbarThemeOverlay" parent="ThemeOverlay.MaterialComponents.Dark.ActionBar">
        <!-- Icon tint color in the toolbar -->
        <item name="iconTint">@android:color/white</item>
    </style>

    <!-- Pop-up theme for toolbar -->
    <style name="CustomPopupTheme" parent="ThemeOverlay.MaterialComponents.Light">
        <!-- Icon tint color for pop-up items -->
        <item name="tint">?colorPrimary</item>
    </style>
</resources>

这就是我们实现工具栏的方式:

<com.google.android.material.appbar.MaterialToolbar
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:elevation="0dp" />

主题会将工具栏图标设置为白色,无需为每个菜单项或单独的可绘制项指定

app:iconTint="@android:color/white"

问题是,当我启动默认的 Android 操作模式时,膨胀的菜单项图标是黑色的,并且我不想更改可绘制本身或膨胀的菜单项的图标颜色。我想从我的主题中更改它,该主题已经适用于没有操作模式的工具栏,但在操作模式下似乎不起作用。

Current Look

我尝试通过我的主题应用操作模式样式,类似于我设计工具栏的样式,但这种方法不起作用。

android material-design android-styles material-components-android android-actionmode
1个回答
0
投票

您可以通过覆盖主题中的

actionBarTheme
属性来设置操作模式的图标色调:

<style name="BaseTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
    ...

    <item name="actionBarTheme">@style/CustomActionMode</item>
</style>
<style name="CustomActionMode" parent="ThemeOverlay.MaterialComponents.Dark.ActionBar">
    <item name="iconTint">@android:color/white</item>
</style>
© www.soinside.com 2019 - 2024. All rights reserved.