温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

Flutter怎么设置透明状态栏和字体颜色

发布时间:2020-07-29 12:24:03 来源:亿速云 阅读:1067 作者:小猪 栏目:移动开发

小编这次要给大家分享的是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(),),);
 }

看完这篇关于Flutter怎么设置透明状态栏和字体颜色的文章,如果觉得文章内容写得不错的话,可以把它分享出去给更多人看到。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI