Android Button setTextColor () parameter call Analysis

Source: Internet
Author: User


Many people may have encountered this problem, that is, when you set the color of the button, the set color is invalid, black or other colors appear, and then many people use colorstatelist instead, the reason is that the parameter call is incorrect.


1st types: TV. setTextColor (android. graphics. Color. RED); // Color class that comes with the System




2nd types: TV. setTextColor (0xffff00ff); // 0xffffff00ff is int type data, grouped by 0x | ff | ff00ff, 0x indicates the color integer, ff indicates the transparency, and ff00ff indicates the color, note: Here, ffff00ff must be represented by 8 colors, and 6 colors such as ff00ff are not accepted.



3rd types: TV. setTextColor (this. getResources (). getColor (R. color. red); // you can set it by obtaining the resource file. R. color. red can also be R. string. red or R. drawable. red, of course, the premise is to make the corresponding configuration in the corresponding configuration file, such:

# FF0000

<Drawable name = "red"> # FF0000

<String name = "red"> # FF0000

Note that in the third method above, do not take the color you have defined as a parameter directly, for example:

TV. setTextColor (R. color. red); in this case, a color error occurs!


If you have any questions, please leave a message and repeat the source.


Related Article

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.