您的位置:首页 > 其它

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

2020-05-01 12:06 2883 查看

注:底色透明是否生效与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(),),);
}

到此这篇关于Flutter 透明状态栏及字体颜色的文章就介绍到这了,更多相关Flutter 状态栏字体颜色内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!

您可能感兴趣的文章:

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息