You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

深色模式下ActionBar默认文本颜色异常及菜单禁用状态显示问题咨询

深色模式下ActionBar文本及菜单禁用状态异常的解决方案

这不属于Android系统Bug,大概率是Theme.MaterialComponents.DayNight.DarkActionBar主题的默认配置未适配你的需求,可通过自定义主题属性解决:

1. 修复深色模式下ActionBar文本颜色过深问题

DayNight.DarkActionBar主题在深色模式下,默认的ActionBar文本颜色可能未自动切换为浅色,需在深色模式的主题配置中明确指定文本颜色:

在res/values-night/styles.xml中添加或修改主题属性:

<style name="AppTheme" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
    <!-- 直接设置ActionBar文本颜色 -->
    <item name="actionBarTextColor">@color/white</item>
    <!-- 若使用MaterialToolbar,可自定义Toolbar样式覆盖标题/副标题颜色 -->
    <item name="toolbarStyle">@style/CustomToolbarStyle</item>
</style>

<style name="CustomToolbarStyle" parent="Widget.MaterialComponents.Toolbar.Primary">
    <item name="titleTextColor">@color/white</item>
    <item name="subtitleTextColor">@color/grey_200</item>
</style>

如果布局中手动使用了MaterialToolbar,需确保它应用了上述自定义样式:

<com.google.android.material.appbar.MaterialToolbar
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"
    style="@style/CustomToolbarStyle" />

2. 修复菜单禁用状态颜色丢失问题

菜单禁用状态的颜色依赖于主题中的colorOnSurfaceDisabled属性,默认配置可能未正确适配深色模式,需在res/values-night/styles.xml中补充:

<style name="AppTheme" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
    <!-- 设置菜单禁用状态的文本颜色 -->
    <item name="colorOnSurfaceDisabled">@color/grey_500</item>
</style>

原理说明

Theme.MaterialComponents.DayNight.DarkActionBar仅提供基础的日夜切换框架,部分细节属性需开发者根据需求自定义配置。上述修改通过明确指定深色模式下的文本、禁用状态颜色,解决了视觉冲突问题。

内容的提问来源于stack exchange,提问作者Davide Torchia

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.08 00:17:19