【问题标题】:How to change the statuts bar color for android in a flutter app?如何在颤振应用程序中更改 android 的状态栏颜色?
【发布时间】:2020-09-20 11:15:02
【问题描述】:

我使用了一个具有灰色背景和黑色作为文本颜色的应用栏的 Scafold。我想让状态栏透明,文本也是黑色的。不幸的是,无论我怎么做,文本颜色都是白色的。看了this的帖子和this的一个,我试过下面的代码,但是文字颜色还是白色的。

  SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle.light.copyWith(
      statusBarColor: Colors.black.withOpacity(0.0), // Color for Android
      statusBarIconBrightness: Brightness.light,
      statusBarBrightness: Brightness.light, 
  ));

更新:

为了更清楚:在模拟器中,栏看起来像这样,这很好:

在我的手机上,文字颜色是白色的,所以你看不到它:

【问题讨论】:

  • 使用appBar: AppBar 小部件并设置颜色transparent

标签: flutter


【解决方案1】:

要更改应用栏主题,可以使用 ThemeData 类的 appBarTheme 属性,要更改 AppBar 的文本颜色,可以使用 textTheme 属性并根据需要进行设置。 AppBar中的文字使用的textstyle是headline6,所以你可以这样做。

    class MyApp extends StatelessWidget {
      @override
      Widget build(BuildContext context) {
        return MaterialApp(
          title: 'Flutter Demo',
          debugShowCheckedModeBanner: false,
          theme: ThemeData(
            primarySwatch: Colors.blue,
             //here we are applying the theme to appbar.
            appBarTheme: AppBarTheme(
              color: Colors.black.withOpacity(0.0),
              brightness: Brightness.dark,
            ),
             //here we are setting the theme to the text
            primaryTextTheme: TextTheme(
                headline6: TextStyle(
              color: Colors.black,
            )),
          ),
          home: MyHomePage(title: 'Flutter Demo Home Page'),
        );
      }
    }

【讨论】:

    【解决方案2】:

    您可以查看下面的简单代码。

     Scaffold(
        backgroundColor: Colors.red,
        appBar: AppBar(
          backgroundColor: Colors.transparent,
          title: Text(
            "Demo",
            style: TextStyle(color: Colors.black),
          ),
          centerTitle: true,
        ),
       body:....,)
    

    【讨论】:

      猜你喜欢
      • 2022-11-13
      • 2021-04-19
      • 1970-01-01
      • 2016-07-06
      • 2014-04-07
      • 1970-01-01
      • 2016-09-08
      • 1970-01-01
      相关资源
      最近更新 更多