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

Flutter从3.16.5升级到3.24.1后Android TitleBar无法隐藏

Flutter 3.24.1升级后Android端原生ToolBar无法隐藏的问题解决

问题原因

  1. Flutter 3.24.1更新了Android端依赖,FlutterFragmentActivity基于AndroidX AppCompat架构运行,原有的旧系统主题@android:style/Theme.Light.NoTitleBar无法覆盖AppCompat组件默认的ActionBar配置,导致原生ToolBar被自动渲染。
  2. 此前仅依赖旧系统主题的NoTitleBar声明,在AndroidX环境下不生效,系统会忽略该设置并加载默认ActionBar。

解决方案

1. 替换主题父类为AndroidX无ActionBar版本

修改styles.xml及values-night/styles.xml,将所有相关主题的父类替换为AndroidX提供的无ActionBar主题,并明确禁用ActionBar和标题:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="LaunchTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
        <item name="android:windowBackground">@drawable/launch_background</item>
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
    </style>
    <style name="NormalTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
        <item name="android:windowBackground">?android:colorBackground</item>
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
    </style>

    <style name="Theme.App.Starting" parent="Theme.SplashScreen">
        <item name="windowSplashScreenBackground">#804EFD</item>
        <item name="postSplashScreenTheme">@style/NormalTheme</item>
        <item name="windowSplashScreenAnimatedIcon">@drawable/ic_splash_layer</item>
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
    </style>
</resources>

若项目未使用Material Components,可将父主题替换为Theme.AppCompat.Light.NoActionBar。

2. 确认Manifest配置无误

保持AndroidManifest.xml中MainActivity的android:theme="@style/Theme.App.Starting"配置不变,确保postSplashScreenTheme指向修改后的NormalTheme。

3. 清理构建缓存并重新运行

执行以下命令清理构建缓存,避免旧配置残留:

flutter clean
./android/gradlew clean

重新启动应用后,原生ToolBar会被隐藏,状态栏保持显示。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.18 13:45:54