简体   繁体   English

如何更改应用栏上文本和图标的颜色 flutter

[英]how to change color of text and icons on appbar flutter

I am having problem while changing the color of text and icon widgets on appbar in flutter.我在 flutter 中更改应用栏上的文本和图标小部件的颜色时遇到问题。

I have tried theme inside the material app but it's not working.我已经在材料应用程序中尝试过主题,但它不起作用。

where this is working: title: Text('Profile', style: TextStyle(color: Colors.black)), But I want to apply this for all appbars.这在哪里工作: title: Text('Profile', style: TextStyle(color: Colors.black)),但我想将它应用于所有应用程序栏。 So where should I make changes in material theme.那么我应该在哪里更改材料主题。

MaterialApp(
          title: "My App",
          theme: ThemeData(
            appBarTheme: AppBarTheme(
              backgroundColor: Color(0xffFCD581),
              brightness: Brightness.dark,
            ),

在此处输入图像描述

how can i change the color of text: profile and icon .我如何更改text: profileicon globally.全球范围内。

setting color of headline6 to Colors.black works.headline6的颜色设置为Colors.black有效。 but it's also making the title text smaller.但它也使标题文本更小。 I can set the fontsize in headline6 and it reflects universally.我可以在headline6中设置字体大小,它反映普遍。 But I think the default size of title that we get with appbar is suitable enough.但我认为我们通过 appbar 获得的默认标题大小已经足够了。 So is there any solution that will only change the color of the appbar text, title without affecting the fontsize .那么有没有什么解决方案只会改变应用栏文本的color appbar text, title而不影响fontsize

Use IconButton as the back button and assign color, for Title use TextStyle and assign a color.使用IconButton作为后退按钮并分配颜色,对于 Title 使用TextStyle并分配颜色。

1. Using AppBar: 1.使用AppBar:

Scaffold(
      appBar: AppBar(
        backgroundColor: Colors.white,
        leading: IconButton(
          icon: Icon(Icons.arrow_back, color: Colors.red),
          onPressed: () => Navigator.of(context).pop(),
        ),
        title: Text("Sample", style: TextStyle(color: Colors.red),),
        centerTitle: true,
      ),

2. Using ThemeData: 2. 使用主题数据:

theme: ThemeData(
    primaryTextTheme: TextTheme(
      headline6: TextStyle(color: Colors.red),
    ),
    appBarTheme: AppBarTheme(
      iconTheme: IconThemeData(color: Colors.red),
    ),
  ),

Output: Output:

在此处输入图像描述

Use the iconTheme and titleTextStyle properties of your AppBarTheme in your MaterialApp widget.MaterialApp小部件中使用AppBarThemeiconThemetitleTextStyle属性。

Here is how to change the color of text and icons:以下是更改文本和图标颜色的方法:

   return Scaffold(
      appBar: AppBar(
        leading: null,
        automaticallyImplyLeading: true,
        centerTitle: true,
        iconTheme: IconThemeData(color: myCustomIconColor), //ICONS
        titleTextStyle: GoogleFonts.lato(
           textStyle: TextStyle(
           fontSize: 23,
           fontWeight: FontWeight.w700,
           color: myCustomTextColor,    //TEXT
         ),
        ),
        title: Text('Settings'),
      ),

Or you can style the Text widget directly and change the color there或者您可以直接设置Text小部件的样式并在那里更改颜色

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM