从主题更改RaisedButton的颜色不起作用 [英] Change color of RaisedButton from theme not working
问题描述
我尝试从themeData
更改所有RaisedButtons的颜色,但拒绝工作.所有其他属性,例如fontSize
和fontWeight
,均已成功更改.仅当themeData
的亮度属性更改为Brightness.dark
时,文本的颜色才从黑色变为白色.
I tried changing the color of all my RaisedButtons from the themeData
but it refused to work. All other properties, such as fontSize
and fontWeight
changed successfully. The color of the text only changes from black to white when the brightness property of themeData
is changed to Brightness.dark
.
有什么办法可以解决这个问题?我可能做错了什么?
Is there a way I can solve this issue? What could I be doing wrong?
这是我的示例代码:
return new MaterialApp(
title: 'Flutter Demo',
theme: new ThemeData(
primaryColor: Color(0XFF212845),
scaffoldBackgroundColor: Color(0XFF212845),
primarySwatch: Colors.yellow,
buttonColor: Color(0XFFF8D320),
textTheme: TextTheme(
button: TextStyle(
color: Colors.green, // This is not working.
fontSize: 30.0,
fontWeight: FontWeight.bold
)
)
),
home:MenuPage(),
);
推荐答案
对于其他遇到此问题的人来说,按钮可能无法更改颜色的一个原因是它被禁用,当您没有onPressed
方法集.
For other people coming to this question, one reason that a button may not change colors is that it is disabled, which happens when you don't have the onPressed
method set.
RaisedButton(
color: Theme.of(context).accentColor,
onPressed: () {}, // <-- need to add this
child: Text(...),
),
这篇关于从主题更改RaisedButton的颜色不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!