Flutter - 更改应用栏的颜色不起作用
Flutter - Changing the color of the appbar is not working
我正在尝试更改 AppBar 的背景颜色,但它不起作用。
根据下图选择颜色0x673AB7
时,AppBar 变成灰色而不是紫色。
import "package:flutter/material.dart";
void main() {
runApp(new ControlleApp());
}
class ControlleApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new MaterialApp(
title: "Controlle Financeiro",
home: new HomePage(),
);
}
}
class HomePage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(
backgroundColor: new Color(0x673AB7),
),
);
}
}
看起来你的颜色是完全透明的。尝试将颜色更改为 0xFF673AB7
正如@Randal 提到的,您使用的是没有 alpha 值的十六进制代码。如果您没有指定它,它将是完全透明的。因此,您可以将前两个值用作 alpha,将其他六个值用作 RGB。
查看 Color
class 源代码。有如下评论:
/// Construct a color from the lower 32 bits of an [int].
///
/// The bits are interpreted as follows:
///
/// * Bits 24-31 are the alpha value.
/// * Bits 16-23 are the red value.
/// * Bits 8-15 are the green value.
/// * Bits 0-7 are the blue value.
///
/// 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)`.
///
/// For example, to get a fully opaque orange, you would use `const
/// Color(0xFFFF9000)` (`FF` for the alpha, `FF` for the red, `90` for the
/// green, and `00` for the blue).
我正在尝试更改 AppBar 的背景颜色,但它不起作用。
根据下图选择颜色0x673AB7
时,AppBar 变成灰色而不是紫色。
import "package:flutter/material.dart";
void main() {
runApp(new ControlleApp());
}
class ControlleApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new MaterialApp(
title: "Controlle Financeiro",
home: new HomePage(),
);
}
}
class HomePage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(
backgroundColor: new Color(0x673AB7),
),
);
}
}
看起来你的颜色是完全透明的。尝试将颜色更改为 0xFF673AB7
正如@Randal 提到的,您使用的是没有 alpha 值的十六进制代码。如果您没有指定它,它将是完全透明的。因此,您可以将前两个值用作 alpha,将其他六个值用作 RGB。
查看 Color
class 源代码。有如下评论:
/// Construct a color from the lower 32 bits of an [int].
///
/// The bits are interpreted as follows:
///
/// * Bits 24-31 are the alpha value.
/// * Bits 16-23 are the red value.
/// * Bits 8-15 are the green value.
/// * Bits 0-7 are the blue value.
///
/// 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)`.
///
/// For example, to get a fully opaque orange, you would use `const
/// Color(0xFFFF9000)` (`FF` for the alpha, `FF` for the red, `90` for the
/// green, and `00` for the blue).