如何更改CircularProgressIndicator的颜色?
颜色的值是Animation< color >的实例,但我希望有一种更简单的方法来改变颜色,没有动画的麻烦。
如何更改CircularProgressIndicator的颜色?
颜色的值是Animation< color >的实例,但我希望有一种更简单的方法来改变颜色,没有动画的麻烦。
当前回答
backgroundColor设置浅色,它看到像浅色背景色的圆,valueColor它是加载颜色,它将显示编译加载圆超过灰色
CircularProgressIndicator(
backgroundColor: Colors.gray,
valueColor: AlwaysStoppedAnimation<Color>(Colors.black)
)
其他回答
这招对我很管用:
CircularProgressIndicator(valueColor: AlwaysStoppedAnimation<Color>(Colors.white))
主题是可以插入到小部件树中的任何位置的小部件。 它用自定义值覆盖当前主题 试试这个:
new Theme(
data: Theme.of(context).copyWith(accentColor: Colors.yellow),
child: new CircularProgressIndicator(),
);
参考:https://gitter.im/flutter/flutter?at=5a84cf9218f388e626a51c2d
backgroundColor设置浅色,它看到像浅色背景色的圆,valueColor它是加载颜色,它将显示编译加载圆超过灰色
CircularProgressIndicator(
backgroundColor: Colors.gray,
valueColor: AlwaysStoppedAnimation<Color>(Colors.black)
)
默认情况下,它从Themedata继承了accentColor
void main() => runApp(new MaterialApp(
theme: ThemeData(
primaryColor: Colors.blue,
accentColor: Colors.blueAccent,
//This will be the color for CircularProgressIndicator color
),
home: Homepage()
));
你可以用你的新颜色改变这个accentColor属性。 另一种方法是像这样使用预定义的主题数据
void main() => runApp(new MaterialApp(
theme: ThemeData.light().copyWith(
accentColor: Colors.blueAccent,
//change the color for CircularProgressIndicator color here
),
home: Homepage()
));
或者,您可以直接在CircularProgressIndicator中更改此颜色属性,如下所示
CircularProgressIndicator(
valueColor: AlwaysStoppedAnimation<Color>(Colors.red),
),
使用progressIndicatorTheme允许为进度指示器定义一个主题。
ThemeData(
progressIndicatorTheme: ProgressIndicatorThemeData(color: Colors.white),
)