- 配置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(); }