软件编程
位置:首页>> 软件编程>> Android编程>> Flutter 透明状态栏及字体颜色的设置方法

Flutter 透明状态栏及字体颜色的设置方法

作者:哇咔 哇咔  发布时间:2021-12-09 21:28:30 

标签:flutter,状态栏,字体颜色

注:底色透明是否生效与android版本有关,版本过低设置无效

1.在main.dart内设置


void main(){
runApp(new MyApp());
if (Platform.isAndroid) {
//设置Android头部的导航栏透明
SystemUiOverlayStyle systemUiOverlayStyle = SystemUiOverlayStyle(
statusBarColor: Colors.transparent, //全局设置透明
statusBarIconBrightness: Brightness.light
//light:黑色图标 dark:白色图标
//在此处设置statusBarIconBrightness为全局设置
);
SystemChrome.setSystemUIOverlayStyle(systemUiOverlayStyle);
}
}

2.单页面设置


appBar: AppBar(
 title: new Text(''),
 elevation: 0,
 brightness: Brightness.dark, //设置为白色字体
 ),

注:设置AppBar之后,单独在build内设置这行代码会失效 SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle.light);

ps:下面看下Flutter修改状态栏颜色以及字体颜色

Flutter沉浸式状态栏


void main() {
runApp(MyApp());
if (Platform.isAndroid) {
// 以下两行 设置android状态栏为透明的沉浸。写在组件渲染之后,是为了在渲染后进行set赋值,覆盖状态栏,写在渲染之前MaterialApp组件会覆盖掉这个值。
SystemUiOverlayStyle systemUiOverlayStyle =
 SystemUiOverlayStyle(statusBarColor: Colors.transparent);
SystemChrome.setSystemUIOverlayStyle(systemUiOverlayStyle);
}
}

Flutter修改状态栏字体颜色

使用AnnotatedRegion包裹Scaffold,可以使得状态栏颜色改变,有dark和light两种


@override
Widget build(BuildContext context) {

return AnnotatedRegion<SystemUiOverlayStyle>(
 value: SystemUiOverlayStyle.light,
 child: Material(child:Scaffold(),),);
}

来源:https://blog.csdn.net/klousYG/article/details/105845683

0
投稿

猜你喜欢

手机版 软件编程 asp之家 www.aspxhome.com