Settings for colors in Android

Source: Internet
Author: User

Scenario One: Create a new XML file and then access it in Java with code (the XML file can be accessed directly)

1. Create a new Color.xml under the Res->values folder (the code defined in this file is #rrggbb)

2. Using code access in Java classes

Course_text.settextcolor (Contextcompat.getcolor (This,r.color.yellow));// getResources().getColor(R.color.color_name) discarded

If it is in an XML file, it can be called directly using R.color.yellow.

Scenario Two: Define the color variable in Java and then use the variable.

1. Define Color variables

private int white = 0xffffffff;//Here The color code is #aarrggbb, the first 2 bits is the transparency

2. Using Color variables

Course_layout.setbackgroundcolor (white);

Settings for colors in Android

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.