gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 07:40:17 24 4
gpt4 key购买 nike

我在 Flutter 中更改 appbar 上文本和图标小部件的颜色时遇到问题。

我在 Material 应用程序中尝试过主题,但它不起作用。

这是在哪里工作:title: Text('Profile', style: TextStyle(color: Colors.black)),但我想将此应用于所有应用栏。那么我应该在哪里更改 Material 主题。

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

enter image description here

如何更改 text: profileicon 的颜色。全局。

headline6 的颜色设置为 Colors.black 有效。但它也使标题文本变小。我可以在 headline6 中设置字体大小,它可以普遍反射(reflect)。但我认为我们使用 appbar 获得的默认标题大小已经足够合适了。那么有没有什么解决方案可以只改变appbar text,titlecolor而不影响fontsize

最佳答案

使用 IconButton 作为后退按钮并指定颜色,对于 Title 使用 TextStyle 并指定颜色。

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。使用 ThemeData:

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

输出:

enter image description here

关于flutter - 如何更改应用栏 flutter 上文本和图标的颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67517799/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com