当前位置: 首页 > news >正文

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即可。

相关文章:

  • Redux中间件redux-thunk和redux-saga的具体区别是什么?
  • spring cloud和dubbo的特点和优劣势
  • 【Linux】【网络】Reactor模式
  • tailwindcss学习01
  • JavaScript中数组的常用方法
  • 【从0做项目】Java搜索引擎(6) 正则表达式鲨疯了优化正文解析
  • 深入剖析Spring MVC
  • CMake技术细节:解决未定义,提供参数
  • 从零到一实现微信小程序计划时钟:完整教程
  • 【ClickHouse 特性及应用场景】
  • ubuntu 执行 sudo apt-get update 报错
  • redis7 for windows的安装教程
  • vue 接口传formdata
  • 基于Java+Swing+Mysql实现旅游管理信息系统
  • Promise异步编程
  • 【阮一峰】6.对象
  • 【阮一峰】8.类
  • 如何写出优秀的测试用例?
  • QT基础七、用纯代码编写界面
  • 使用Keras构建图像分类模型的入门指南
  • 大外交丨3天拿下数万亿美元投资,特朗普在中东做经济“加法”和政治“减法”
  • 词条数量大幅扩充,《辞海》第八版启动编纂
  • 海昏侯博物馆展览上新,“西汉帝陵文化展”将持续展出3个月
  • 新版城市规划体检评估解读:把城市安全韧性摆在更加突出位置
  • 人形机器人灵犀X2掌握新技能:有了“内心戏”,还会拳脚功夫
  • 中国进出口银行:1-4月投放制造业中长期贷款超1800亿元