如何使用主题通用更改AppBar的文本颜色,FAB的图标颜色? [英] How to change text color of AppBar, icon color of FAB universally using theme?

查看:146
本文介绍了如何使用主题通用更改AppBar的文本颜色,FAB的图标颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以将AppBar的背景色设置为Colors.amber.这将自动将文本颜色设置为黑色.我知道可能会出现可访问性问题,但是无论如何我都希望文本颜色为白色.

I am able to set the background color of AppBar to Colors.amber. This automatically sets the text color to Black. I am aware of the accessibility issues that may arise but anyways I want the text color to be White.

我仍然可以从AppBar设置文本颜色,但是我想对其进行通用设置.

I am still able to set the text color from the AppBar but I would like to set it universally.

这是我用于应用程序的主题.

Here's the theme I'm using for my app.

title: 'Flutter Demo',
theme: new ThemeData(
  primarySwatch: Colors.amber,
  textTheme: Theme.of(context).textTheme.apply(
    bodyColor: Colors.white,
    displayColor: Colors.white,
  ),
),

推荐答案

我认为最简单的方法是为正在使用的主题调整标题颜色:

I think the most straightforward way of doing this is to adjust the title color for the theme that you are working with:

theme: new ThemeData(
  primarySwatch: Colors.grey,
  primaryTextTheme: TextTheme(
    headline6: TextStyle(
      color: Colors.white
    )
  )
)

这篇关于如何使用主题通用更改AppBar的文本颜色,FAB的图标颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆