Flutter设置(appBar)状态栏背景色,状态栏字体

 Container(
      height: ScreenUtil.screenHeight,
      color: Color(0xFF007AFF),
      child: AnnotatedRegion<SystemUiOverlayStyle>(
        // 设置 AppBar 颜色属性
        value:SystemUiOverlayStyle.light,
      ),
    );

如  AnnotatedRegion 下 value 属性值就是对应的 light模式还是dark模式,如果Container 是最外层容器,状态栏背景色就是透明的,看到的效果就是上面的color色值,也可以在initState()时给状态栏设置指定的背景色

SystemChrome.setSystemUIOverlayStyle(
    SystemUiOverlayStyle(statusBarColor: Colors.red)); 

setSystemUIOverlayStyle 即设置状态栏颜色

 设置状态栏字体颜色

Widget build(BuildContext context) {
    ScreenUtil.init(context, width: 360, height: 640);
    FToast().init(context);
    return Scaffold(
      backgroundColor: Colors.redAccent,
      appBar: AppBar(
        title: Text('Title dark'),
        centerTitle: true,
        elevation: 0,
        bottom: null,
        backgroundColor: Colors.orangeAccent,
        brightness:
             Brightness.dark,
      ),
      body: Container(),
    );
  }

 Widget build(BuildContext context) {
    ScreenUtil.init(context, width: 360, height: 640);
    FToast().init(context);
    return Scaffold(
      backgroundColor: Colors.blue,
      appBar: AppBar(
        title: Text('Title light'),
        centerTitle: true,
        elevation: 0,
        bottom: null,
        backgroundColor: Colors.orangeAccent,
        brightness:
             Brightness.light,
      ),
      body: Container(),
    );
  }

效果图

如果AppBar属性toolbarHeight设置了为 0 ,则brightness相关属性就会失效.Scaffold 也有适配底部输入框不被键盘遮挡

综上可以使用 AnnotatedRegion SystemChrome 或者 Scaffold 使用对应属性进行状态栏相关属性设置.

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值