方法1:修改MainActivity
在MainActivity.kt或MainActivity.java,判断一下版本号然后将状态栏颜色修改设置成透明,因为他本身是黑色半透明:
Kotlin:
class MainActivity: FlutterActivity() {
override fun configureFlutterEngine(@NonNull flutterEngine: FlutterEngine) {
GeneratedPluginRegistrant.registerWith(flutterEngine);
}
override fun onCreate(saveInstanceState:Bundle?){
super.onCreate(saveInstanceState);
if(Build.VERSION.SDK_INT>=Build.VERSION_CODES.LOLLIPOP){
window.statusBarColor=0
}
}
}
Java:
public class MainActivity extends FlutterActivity {
@Override
public void configureFlutterEngine(@NonNull FlutterEngine flutterEngine) {
GeneratedPluginRegistrant.registerWith(flutterEngine);
}
// 设置状态栏沉浸式透明(修改flutter状态栏黑色半透明为全透明)
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
getWindow().setStatusBarColor(0);
}
}
}
方法2:通过setSystemUIOverlayStyle方法设置透明状态栏
修改main.dart文件在main()方法中添加如下代码
if (Platform.isAndroid) {
// 设置android状态栏为透明的沉浸,在渲染之前MaterialApp组件会覆盖掉这个值。
SystemUiOverlayStyle systemUiOverlayStyle = const SystemUiOverlayStyle(
statusBarColor: Colors.transparent, //状态栏的颜色根据需要更改
);
SystemChrome.setSystemUIOverlayStyle(systemUiOverlayStyle);
}
方法3:通过systemOverlayStyle属性设置透明状态栏
Scaffold(
appBar: AppBar(
title:Text(widget.title),
systemOverlayStyle: SystemUiOverlayStyle(statusBarColor: Colors.transparent),
),
)
方法4:通过修改appbar样式实现
实现方式查看Flutter修改AppBar的主题