Android in code four ways to set the background color of controls (and TextView text colors)

Source: Internet
Author: User
Tags color representation

http://blog.csdn.net/fth826595345/article/details/9208771 ThemesTextView

Reprint Please specify source: http://blog.csdn.net/fth826595345/article/details/9208771

Directly on the code, comment commentary:

TextView ttext= (TextView) Findviewbyid (r.id.textv_name);  The 1th type:  Ttext.settextcolor (Android.graphics.Color.RED);//system comes with the color class  The 2nd type: Ttext.settextcolor (0XFFFF00FF);//0xffff00ff is the data of type int, group the 0x|ff|ff00ff,0x is the mark that represents the color integer, FF is the transparency, the FF00FF represents the color, Note: Here ffff00ff must be a color representation of 8, do not accept ff00ff color representation of this 6.   The 3rd type: Ttext.settextcolor (Android.graphics.Color.parseColor ("#87CEFA")); or using the color class; The 4th type: Ttext.settextcolor (This.getresources (). GetColor (r.color.red));     /* Set up by obtaining a resource file. Depending on the situation r.color.red can also be r.string.red or r.drawable.red, * It is necessary to make the corresponding configuration in the corresponding configuration file, such as (XML tag):  *   * << Span class= "title" >color name= "red" > #FF0000 < /color>    <drawable name= "red" > #FF0000 </drawable>    <string name= "red" > #FF0000 </string >*/               

Android Four ways to set the background color of controls (and TextView text colors) in code

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.