Flutter适配安卓刘海、水滴屏显示全屏

  • 配置Android
    找到android/app/src/main/res/values目录,打开styles.xml
    将shortEdges放到style标签内。
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <!-- Theme applied to the Android Window while the process is starting -->
    <style name="LaunchTheme" parent="@android:style/Theme.Black.NoTitleBar">
        <!-- Show a splash screen on the activity. Automatically removed when
             Flutter draws its first frame -->
        <item name="android:windowBackground">@drawable/launch_background</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:color/white</item>
        /// 放这里
        <item name="android:windowLayoutInDisplayCutoutMode">shortEdges</item>
    </style>
</resources>

LaunchTheme指的是启动页的主题,也就是我们常说的Splash页面。如果需要启动页全屏就放在里面。
NormalTheme代表正常页面的主题。
根据需求,我们可以放在2个不同的地方。

  • Flutter中设置SystemChrome.setEnabledSystemUIOverlays([]),隐藏状态栏和底部导航栏
@override
initState() {
	  /// 初始化时隐藏
      SystemChrome.setEnabledSystemUIOverlays([]);
      super.initState();
}

@override
void dispose() { 
	/// 页面关闭时恢复正常设置
  	SystemChrome.setEnabledSystemUIOverlays(SystemUiOverlay.values);
    super.dispose();
}
  • 4
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值