Android records a common setTextColor bug, androidbug

Source: Internet
Author: User

Android records a common setTextColor bug, androidbug

I accidentally made a mistake when writing code today. After careful inspection, we can only record it to prevent you from making the same mistake.

The Code is as follows:

remote.setTextColor(summaryId, R.color.news_have_read);

As shown above, the Code cannot display the color normally in any case. You have to switch to the following code:

remote.setTextColor(summaryId,0xfdfdfdfd);

There is always a lot of trouble to write color values .. In color. xml.

Finally, we can find that the write is the most correct.

remote.setTextColor(summaryId, mContext.getResources().getColor(R.color.news_is_have_read));

In remote. setTextColor (summaryId, R. color. news_have_read); in this Code, R. color. news_have_read the int value generated through eclipse is not a true color value and must be passed through mContext. getResources (). getColor obtains the true hexadecimal color value #255 #255 #255 #255.


The following table is displayed in Android:

TableLayout t; TableRow row; @ Overridepublic void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. activity_main); t = (TableLayout) findViewById (R. id. t); int z [] = {4, 3, 5}; ArrayList <View> v = new ArrayList <View> (); for (int x = 0; x <3; x ++) {row = new TableRow (this); for (int I = 0; I <z [x]; I ++) {TextView t1 = new TextView (this), t1.setText ("32323232"), t1.setTextColor (Color. BLACK); row. addView (t1);} t. addView (row );}}

Android development, there is no Color xml file in the res/Values folder in the environment, so I created a new problem.

Resources. getColor () check if your reference path is correct?
Android.blog.51cto.com/268543/302529i would like to recommend a special blog to you to illustrate the resource folder.

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.