Android端Flutter NativeSplashScreen状态栏与导航栏透明方案问询
Android端Flutter NativeSplash启动屏状态栏/导航栏透明解决方案
步骤1:自定义启动主题
在android/app/src/main/res/values/styles.xml中添加自定义启动主题:
<style name="CustomSplashTheme" parent="Theme.MaterialComponents.Light.NoActionBar"> <!-- 开启状态栏/导航栏透明 --> <item name="android:windowTranslucentStatus">true</item> <item name="android:windowTranslucentNavigation">true</item> <!-- 设置状态栏/导航栏颜色为透明 --> <item name="android:statusBarColor">@android:color/transparent</item> <item name="android:navigationBarColor">@android:color/transparent</item> <!-- 允许窗口绘制系统栏背景 --> <item name="android:windowDrawsSystemBarBackgrounds">true</item> <!-- 隐藏ActionBar --> <item name="windowActionBar">false</item> <item name="windowNoTitle">true</item> </style>
步骤2:配置flutter_native_splash使用自定义主题
在项目根目录的pubspec.yaml中,修改flutter_native_splash的配置,指定使用上述自定义主题:
flutter_native_splash: # 保留你原有的图片、背景色等配置 android_theme: "@style/CustomSplashTheme"
步骤3:调整启动屏布局延伸到系统栏
找到android/app/src/main/res/drawable/launch_background.xml(深色模式对应drawable-night目录下的同名文件),确保启动屏内容能延伸到状态栏和导航栏区域:
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@color/your_splash_bg_color" /> <item> <bitmap android:gravity="center" android:src="@drawable/your_splash_image" /> </item> </layer-list>
如果你的启动屏布局是LinearLayout等容器,需在根标签添加android:fitsSystemWindows="false"
步骤4:重新生成启动屏并测试
执行命令重新生成启动屏资源:
flutter pub run flutter_native_splash:create
运行项目即可查看透明效果。
额外注意事项
- 若项目支持深色模式,需在
values-night/styles.xml中同步添加相同的自定义主题配置。 - 无需设置
android:windowFullscreen,否则会隐藏状态栏/导航栏,仅透明需求不需要此属性。
内容的提问来源于stack exchange,提问作者Jackie
相关产品推荐
相关产品推荐

