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

Flutter/Android:如何移除小米安卓深色模式下启动页的暗化层?

解决Flutter Android启动页深色模式下的暗化层问题

问题场景

当前Android端配置启动主题为LaunchTheme,并在values-night目录下定义了对应样式。期望启动页呈现纯净浅色背景,但实际开启系统深色模式时,启动页出现暗化覆盖层;使用#ffffff作为窗口背景可避免黑底,但设置?android:colorBackground会直接显示黑色背景。

现有配置:
AndroidManifest中主题配置:

android:theme="@style/LaunchTheme"

values-night目录下的样式文件:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="LaunchTheme" parent="@android:style/Theme.Black.NoTitleBar">
        <item name="android:windowBackground">@drawable/launch_background</item>
        <item name="android:forceDarkAllowed">false</item>
        <item name="android:windowFullscreen">true</item>
        <item name="android:windowDrawsSystemBarBackgrounds">true</item>
        <item name="android:windowLayoutInDisplayCutoutMode">shortEdges</item>
    </style>
    <style name="NormalTheme" parent="@android:style/Theme.Black.NoTitleBar">
        <item name="android:windowBackground">#ffffff</item>
    </style>
</resources>

问题原因

当前LaunchTheme继承自深色主题Theme.Black.NoTitleBar,即便设置了forceDarkAllowed=false,系统仍会基于父主题的深色属性对浅色背景启动页施加暗化处理;而?android:colorBackground在深色模式下会映射为系统默认深色,导致黑底。

解决方案

1. 更换父主题并强制浅色模式

修改values-night下的LaunchTheme,更换父主题为浅色主题,并添加强制浅色模式的配置:

<style name="LaunchTheme" parent="@android:style/Theme.Light.NoTitleBar">
    <item name="android:windowBackground">@drawable/launch_background</item>
    <item name="android:forceDarkAllowed">false</item>
    <item name="android:windowFullscreen">true</item>
    <item name="android:windowDrawsSystemBarBackgrounds">true</item>
    <item name="android:windowLayoutInDisplayCutoutMode">shortEdges</item>
    <!-- 强制主题使用浅色模式,不受系统深色设置影响 -->
    <item name="android:colorMode">light</item>
</style>

2. 统一启动页背景资源

确保launch_background仅存在于默认的drawable目录,不要在drawable-night下创建对应的深色版本,避免系统自动切换暗化背景。

3. 修正NormalTheme配置

如果启动页之后的窗口也需要保持浅色,同步修改NormalTheme:

<style name="NormalTheme" parent="@android:style/Theme.Light.NoTitleBar">
    <item name="android:windowBackground">#ffffff</item>
    <item name="android:forceDarkAllowed">false</item>
</style>

关键提示

  • android:colorMode="light"是核心配置,它会强制主题脱离系统深色模式的影响,彻底消除暗化层。
  • 避免继承深色父主题,这类主题自带的深色属性会增加系统自动暗化的概率。

内容的提问来源于stack exchange,提问作者Flutter kyoto

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.12 22:57:43