Resources - color

In Android with a color to represent the 32-bit integer, 32-bit integer contains 4 bytes, of which the first byte represents the color of the transparency (Alpha), 0 represents a completely transparent, 0xFF is completely opaque. 2,3,4 byte representing the color red in the RGB color space (R), green (G) and blue (B) values ​​of three color components, the color component representing no 0, representing the color 0xFF component is maximized. For example 0xCCFF0000 red represents 80% transparency.

#RGB

#ARGB

#RRGGBB

#AARRGGBB

file path

res/values/colors.xml

Reference

java中:R.color.color_name

xml中:@Color/color_name

Within an XML # adding a color to represent the color value, e.g. # FFA1A100. If transparency to 0xFF, and that is completely opaque, the transparency may be omitted, for example, can be written as # FFA1A100 # A1A100.

XML tags can be acquired in good color configuration, the integer value can be directly used to represent a color by the color getColor ().

Note that, when the direct use of an integer value of a color to represent the color, transparency can not be omitted when 0xFF, otherwise they will think that transparency is 0, that is completely transparent, which cause the color can not be displayed.

Such as XML in color # A1A100, the code should be written 0xFFA1A100, but can not be written 0xA1A100.

listView.setDivider(new ColorDrawable(0xFFFF0000));

listView.setDividerHeight(1);

Custom Color Syntax

5777390-116541588066b6d1.png
5777390-acf2e65816dca6b8.png
5777390-1abeeed032b4e123.png

The following is a comparison table of transparency, transparency hex

5777390-56dff5ec415d7a0b.png
5777390-7bd730a43f9bc4c2.png
5777390-fb36c0260133c679.png
5777390-49b860e40ade5466.png
5777390-1d40db44011c1e78.png

Reproduced in: https: //www.jianshu.com/p/e2b7cbd9c7f7

Guess you like

Origin blog.csdn.net/weixin_33737134/article/details/91244165