简体   繁体   English

如何在颤动中将状态栏图标和文本颜色更改为黑色?

[英]How to change the status bar icons and text color to black in flutter?

I am using white background for App Bar in flutter and how can I change the status bar icon colors to black,我在颤动中为 App Bar 使用白色背景,如何将状态栏图标颜色更改为黑色,

I am using this code to change the status bar color,我正在使用此代码更改状态栏颜色,

SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle.dark.copyWith(
  statusBarColor: Colors.white,
  statusBarIconBrightness: Brightness.light,
));

You also need to set to brightness in AppBar if you are using one.如果您正在使用,您还需要在 AppBar 中设置为brightness Eg.例如。

appBar: AppBar(
        backgroundColor: Colors.white,
        brightness: Brightness.dark,
),

You can checkout detailed answer here: How to change status bar color in Flutter?您可以在此处查看详细答案: 如何在 Flutter 中更改状态栏颜色?

Hi, in my project, I use the following (use Brightness was obsolete)嗨,在我的项目中,我使用以下(使用Brightness已过时)

Without AppBar:没有 AppBar:
return AnnotatedRegion<SystemUiOverlayStyle>(
            //Set status bar icon color
            value: your_condition
                ? SystemUiOverlayStyle.dark.copyWith(
                    statusBarColor: your_color,
                    //statusBarIconBrightness: Brightness.light,
                  )
                : SystemUiOverlayStyle.light.copyWith(
                    statusBarColor: your_color,
                    //statusBarIconBrightness: Brightness.light,
                  ),
            child: your_widget);
With AppBar:使用 AppBar:
return AppBar(
    elevation: 0.0,
    systemOverlayStyle: your_condition ? SystemUiOverlayStyle.dark : SystemUiOverlayStyle.light,
    backgroundColor: your_color,
);
  • You can use a combination of the two methods above to achieve your goal您可以结合使用上述两种方法来实现您的目标

Flutter 2.4.0+ UPDATE颤振 2.4.0+ 更新

Since flutter 2.4.0 brightness: Brightness.dark is deprecated.由于颤振 2.4.0 brightness: Brightness.dark不推荐使用brightness: Brightness.dark

It has been replaced by systemOverlayStyle: SystemUiOverlayStyle.dark它已被systemOverlayStyle: SystemUiOverlayStyle.dark取代systemOverlayStyle: SystemUiOverlayStyle.dark

How to use:如何使用:

import 'package:flutter/services.dart';

appBar: AppBar(
    systemOverlayStyle: SystemUiOverlayStyle.dark,
    elevation: 0.0,
),

Set SystemUiOverlayStyle.dark if you want black icons.如果需要黑色图标,请设置SystemUiOverlayStyle.dark

Set SystemUiOverlayStyle.light if you want white icons.如果需要白色图标,请设置SystemUiOverlayStyle.light

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何自定义状态栏图标和文字颜色? 例如状态栏背景:白色,状态栏图标颜色,文字:红色 - How to customize status bar icons and text color? E.g. status bar background: white, status bar icon color, and text: red 如何在Android中更改状态栏文字颜色? - how to change the status bar text color in android? 将状态栏项目(符号)的颜色更改为黑色 - Change the color of Status bar items (symbols) to black flutter如何根据设置的主题更改状态栏图标和文字颜色? - How to change status bar icon and text color in flutter based on theme been set? 如何在颤动中更改原生闪屏的状态栏颜色? - How to change status bar color of native splash screen in flutter? 如何使状态栏变为白色并带有黑色图标? - How can I make the status bar white with black icons? Android Full Height DialogFragment with transparent status bar color 如何更改状态栏文本颜色? - Android Full Height DialogFragment with transparent status bar color how to change status bar text color? 如何更改 Android 中状态栏的颜色文本? - How can I change color text of status bar in Android? Android:是否可以在Android Lollipop中更改状态栏中图标的颜色 - Android: Is it possible to change the color of icons in status bar in Android Lollipop 在黑色和白色之间切换状态栏文本颜色 - Toggle status bar text color between black and white
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM