如何在 Flutter 中使用 RGB 颜色?
How do I use RGB color in Flutter?
我正尝试像这样使用它,但它没有给我文本上的颜色。
Color.fromARGB(1, 239 ~/ 255, 58 ~/ 255, 121 ~/ 255)
尝试使用
Color.fromRGBO(38, 38, 38, 0.4)
其中 r
代表 Red
,g
代表绿色,b
代表 Blue
,o
代表 opacity
示例:
Container(
width: double.infinity,
height: double.infinity,
color: Color.fromRGBO(38, 38, 38, 0.4),
child: Center(
child: CircularProgressIndicator(),
))
我将此代码块用于我的个人项目,以便使用 Color.fromRGBO
显示具有特定颜色的文本,第一个参数是 Red
,第二个是 Green
,第三个是 Blue
,最后一个参数定义 Opacity
.
Text(
"This is a sample text",
textAlign: TextAlign.center,
style: TextStyle(
color: Color.fromRGBO(255, 179, 102, 1)
)
)
您也可以使用十六进制表示Color(0XFF212845)
。
来源评论
/// In other words, if AA is the alpha value in hex, RR the red value in hex,
/// GG the green value in hex, and BB the blue value in hex, a color can be
/// expressed as const Color(0xAARRGGBB)
.
增加 alpha(第一个参数)以便您可以看到它。
例子:-
颜色:Color.fromARGB(255, 255, 0, 0)
如果要将不透明度指定为介于 0.0(透明)和 1.0(完全不透明)之间的双精度值,请使用 Color.fromRGBO()
。不透明度值是最后一个参数。
Color.fromRGBO(int r, int g, int b, double opacity)
但是,如果您想将不透明度指定为介于 0(透明)和 255(完全不透明)之间的整数值,请使用 Color.fromARGB()
。不透明度值是第一个参数。
Color.fromARGB(int a, int r, int g, int b)
两种方法的r
、g
、b
参数均为0~255之间的整数值
我正尝试像这样使用它,但它没有给我文本上的颜色。
Color.fromARGB(1, 239 ~/ 255, 58 ~/ 255, 121 ~/ 255)
尝试使用
Color.fromRGBO(38, 38, 38, 0.4)
其中 r
代表 Red
,g
代表绿色,b
代表 Blue
,o
代表 opacity
示例:
Container(
width: double.infinity,
height: double.infinity,
color: Color.fromRGBO(38, 38, 38, 0.4),
child: Center(
child: CircularProgressIndicator(),
))
我将此代码块用于我的个人项目,以便使用 Color.fromRGBO
显示具有特定颜色的文本,第一个参数是 Red
,第二个是 Green
,第三个是 Blue
,最后一个参数定义 Opacity
.
Text(
"This is a sample text",
textAlign: TextAlign.center,
style: TextStyle(
color: Color.fromRGBO(255, 179, 102, 1)
)
)
您也可以使用十六进制表示Color(0XFF212845)
。
来源评论
/// In other words, if AA is the alpha value in hex, RR the red value in hex,
/// GG the green value in hex, and BB the blue value in hex, a color can be
/// expressed asconst Color(0xAARRGGBB)
.
增加 alpha(第一个参数)以便您可以看到它。 例子:- 颜色:Color.fromARGB(255, 255, 0, 0)
如果要将不透明度指定为介于 0.0(透明)和 1.0(完全不透明)之间的双精度值,请使用 Color.fromRGBO()
。不透明度值是最后一个参数。
Color.fromRGBO(int r, int g, int b, double opacity)
但是,如果您想将不透明度指定为介于 0(透明)和 255(完全不透明)之间的整数值,请使用 Color.fromARGB()
。不透明度值是第一个参数。
Color.fromARGB(int a, int r, int g, int b)
两种方法的r
、g
、b
参数均为0~255之间的整数值