Material 设计的 Android 中的百分比颜色

Percent color in Android for Material Design

在 Google 的 material 设计规范中,我看到指定为百分比的颜色:

To convey a hierarchy of information, you can use different shades for text. The standard alpha value for text on a white background is 87% (#000000). Secondary text, which is lower in the visual hierarchy, should have an alpha value of 54% (#000000).

我不明白这些百分比是如何计算的。例如,如果背景颜色是白色,那么文字的颜色是什么?

如果我的背景是#607D8B 会怎么样。我的文字颜色是什么?是否只是将不透明度 (alpha) 设置为百分比的背景颜色?

您的颜色 (#607D8B) 是 RGB,而文档指的是 ARGB (#FF607D8B),百分比指的是 alpha 通道。 FF255 十进制。对于 pressed 你想要 40% 的 alpha,这使得 102,十六进制应该是 66。所以按下的颜色应该是#66607D8B

我想这意味着如果你使用#607D8B 作为你的颜色那么:

悬停:20% #607D8B = #33607D8B

按下:40% #607D8B = #66607D8B

等等

here 是具有十六进制 alpha 值的 table

此外,如果您想知道基于 RGBA 值和背景颜色的颜色的 RGB 十六进制值,this 网站可能会帮助您。

颜色visibility的百分比

当我们使用十六进制格式指定任何颜色时:

First 2 digit : visibility

After 6 digit : RRGGBB

所以,计算例子是:

(87)% of (100) decimel = 87 %   ->    convert to (87)% of (256) in hex 222.72 rounding to 223 which is (DF) in hex

所以你的颜色代码=#DF607D8B -- primary

同理,任何百分比都应转换为hex

你可以查看 table : here

Kushal 的回答虽然包含很好的信息,但根据您问题的上下文,可能会有些误导。

The standard alpha value for text on a white background is 87% (#000000).

您提供的引用文本明确指出百分比指的是 alpha 值。


I don't understand how these percentages work. For example, if the background color is white, what is the color of the text?

在此示例中,背景为白色 (#FFFFFF),文本为黑色 (#000000)。文本的 alpha 值为 0.87.


What if my background were say #607D8B. What would my text color be? Is it just the background color with the opacity (alpha) set to the percentage?

那将是蓝灰色,在我看来属于 "dark background" 类别。使用完全不透明的白色文本。


Text opacity
Text may be displayed with different degrees of opacity to convey how important certain information is relative to other information. The level of opacity used for text depends on whether your background is darker or lighter.

有关详细信息,请参阅指南的 this 部分。

此外,如果您从 here 中选择颜色,请记下他们在上面使用的颜色字体。