In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article is about the sample analysis of Android color in XML files and java code. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
1. Use constants of the Color class, such as:
Int color = Color.BLUE;// create a blue using the color provided by Android int color = Color.RED; int color = Color.WHITE
2. Build through ARGB, such as:
Int color = Color.argb (127,255,0,255); / / translucent purple where the first parameter is transparent, 0 is completely transparent, and 255th (ff) is completely opaque; the last three bits represent the value of RGB, respectively.
3. Use XML resource files to define colors
This method has good scalability and is easy to modify and share, such as creating a color.xml under the values directory:
# 7fff00ff
Defines a color called mycolor, which can be obtained elsewhere by referencing mycolor, as shown in
In the textView definition:
Android:textColor= "@ drawable/mycolor"
You can use getColor in the ResourceManager class in the Java code to get the color:
Int color = getResources () .getColor (R.color.mycolor)
This is the same as the value obtained by the second method, where the getResources () method returns the ResourceManager class instance of the currently active Activity.
Note: the XML definition method accepts 6-bit and 8-bit representations, and it must begin with #. The first two bits of the 8-bit definition are transparent. (for simplicity, it can also be abbreviated), for example:
# f00#0000ff#f0f0#ffffff00
4. Define color values directly, such as:
Int color = 0xff00ff00
This method must start with 0x instead of using our usual #. Unlike method 3, values must also be represented in 8 bits and do not accept 6-bit colors. Group 0x | ff | ff00ff,0x is a marker for color integers, ff for transparency, and ff00ff for RGB color values.
Thank you for reading! This is the end of this article on "sample analysis of Android color in XML files and java code". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it out for more people to see!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.