我们如何在颤振中更改应用栏背景颜色 [英] How can we change appbar background color in flutter

查看:22
本文介绍了我们如何在颤振中更改应用栏背景颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为应用程序设置一个通用主题,因此我需要将 appbar 颜色更改为表示十六进制代码的颜色 #0f0a1a

I am trying to set a common theme for app so I need to change appbar color as a color that indicates hex code #0f0a1a

const MaterialColor toolbarColor = const MaterialColor(
    0xFF151026, const <int, Color>{0: const Color(0xFF151026)});

我尝试使用这段代码来制作自定义颜色,但失败了.如何从 themeData 执行此操作?

I try this piece of code to make a custom color but fails. How can I do this from themeData?

推荐答案

声明你的颜色:

const primaryColor = Color(0xFF151026);

MaterialApp 级别(将改变整个应用程序中的 AppBar 颜色)更改 primaryColor

In the MaterialApp level (will change the AppBar Color in the whole app ) change primaryColor

return MaterialApp(
  title: 'Flutter Demo',
  theme: ThemeData(
   primaryColor: primaryColor,
   ),
  home: MyApp(),
);

如果你想在 Widget 级别更改它,请修改 backgroundColor

and if you want to change it on the Widget level modify the backgroundColor

  appBar: AppBar(
    backgroundColor: primaryColor,
  ),

这篇关于我们如何在颤振中更改应用栏背景颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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