解决碍眼:
1、修改主题:
<style name="LaunchTheme" parent="@android:style/Theme.Translucent.NoTitleBar">
<!-- Show a splash screen on the activity. Automatically removed when
Flutter draws its first frame -->
<item name="android:windowBackground">@drawable/launch_background</item>
</style>
2、修改launch_background.xml文件(v21也要改)
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<!-- <item>-->
<!-- <bitmap android:gravity="fill" android:src="@drawable/background"/>-->
<!-- </item>-->
<item>
<bitmap
android:gravity="fill"
android:scaleType="fitXY"
android:src="@drawable/splash"
/>
</item>
</layer-list>
3、修改MainActivity
class MainActivity : FlutterActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState);
statusBarHide(this);
}
/**
* 设置Activity的statusBar隐藏
* @param activity
*/
fun statusBarHide(activity: Activity) {
// 代表 5.0 及以上
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
val decorView: View = activity.window.decorView
val option: Int = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
decorView.setSystemUiVisibility(option)
activity.window.statusBarColor = Color.parseColor("#A5D7F9");
val actionBar = activity.actionBar
actionBar.let {
it?.let {
it.hide();
}
}
return
}
// versionCode > 4.4 and versionCode < 5.0
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT && Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
activity.window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS)
}
}
}
4、修改main.dart文件
void main() {
setOverlayStyle();
runApp(const MyApp());
}
//沉浸式状态栏
void setOverlayStyle(){
//沉浸式状态栏
if(Platform.isAndroid) {
SystemChrome.setSystemUIOverlayStyle(
SystemUiOverlayStyle(statusBarColor: Colors.transparent));
}
}
|