flutter 状态栏不显示 问题解决办法

本篇文章主要讲解flutter 状态栏不显示 问题解决办法,通过本篇文章你可以快速解决遇到的这个问题。

日期:2025年2月15日

作者:任聪聪

现象说明:

现象1:不显示顶部的状态栏

现象2:不显示底部的 按钮

其他说明:

1、尝试通过AppBar解决无效。

2、设置全局样式参数无效。

复制代码
  // 设置系统UI模式为正常模式,显示状态栏和导航栏
  SystemChrome.setEnabledSystemUIMode(SystemUiMode.edgeToEdge);

  // 设置状态栏样式
  SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
    statusBarColor: Colors.transparent, // 设置状态栏颜色为透明
    statusBarIconBrightness: Brightness.dark, // 设置状态栏图标为深色
  ));

备注:总之很多方法都无效的情况。

问题原因:

这是由于位于:flutter\android\app\src\main\res\values-night\styles.xml文件下开启了全屏配置导致。

解决办法:

复制代码
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <!-- Theme applied to the Android Window while the process is starting when the OS's Dark Mode setting is on -->
    <style name="LaunchTheme" parent="@android:style/Theme.Black.NoTitleBar">
        <!-- Show a splash screen on the activity. Automatically removed when
             the Flutter engine draws its first frame -->
        <item name="android:windowBackground">@drawable/launch_background</item>
        <item name="android:forceDarkAllowed">false</item>
        <item name="android:windowFullscreen">false</item>
        <item name="android:windowDrawsSystemBarBackgrounds">true</item>
        <item name="android:windowLayoutInDisplayCutoutMode">shortEdges</item>
    </style>
    <!-- Theme applied to the Android Window as soon as the process has started.
         This theme determines the color of the Android Window while your
         Flutter UI initializes, as well as behind your Flutter UI while its
         running.

         This Theme is only used starting with V2 of Flutter's Android embedding. -->
    <style name="NormalTheme" parent="@android:style/Theme.Black.NoTitleBar">
        <item name="android:windowBackground">?android:colorBackground</item>
    </style>
</resources>

说明: <item name="android:windowFullscreen">false</item> 此类目改为false即可。

相关推荐
好的佩奇8 小时前
蓝牙之通信架构
android·flutter·蓝牙
FlightYe8 小时前
视界原理之3D视频(四):裸眼、眼镜和头显
android·linux·c++·3d·ffmpeg·音视频
幸运小猿9 小时前
模拟慢上传-处理超时重试image 丢失线上问题
前端·javascript·html
诸神黄昏EX9 小时前
Android fw BatteryService
android
alexhilton10 小时前
提升 Android Compose 页面的流畅度
android·kotlin·android jetpack
撩得Android一次心动11 小时前
Android中Gradle网络下载超时、更改存放位置(解决方案)
android·gradle
速易达网络12 小时前
ECharts 图表制作完全指南:从零到可视化实战
前端·javascript·echarts
HQL_seven12 小时前
【Activity】Android Activity详解
android
AI2中文网12 小时前
安卓 15/16 手机软键盘遮挡输入框、布局顶不上去?已解决:重新编译即可
android·智能手机
字节暗面13 小时前
Android APP 加固横评记录:爱加密、梆梆、网易易盾与腾讯 ACE
android·逆向工程·加固