Android modifies the global default color of TextView.

Source: Internet
Author: User

If the color of most textviews in your application is red or other colors, you can set a color for each TextView, or there are other better ways, here we will teach you how to modify the default color of TextView.

Of course, let's start with TextView.

View the TextView source code and find the following code:
 

This Code indicates that the default style name of TextView is textViewStyle. Then, find textViewStyle under Theme in Themes. xml, and you can find the following code:
@android:style/Widget.TextView
In addition, the TextViewStyle values of different themes are different. Where:
  • Below Theme is @ android: style/Widget. TextView;
  • Theme. Height does not have this value. I don't know why;
  • Theme. Holo: @ android: style/Widget. Holo. TextView;
  • Theme. Holo. Light: @ android: style/Widget. Holo. Light. TextView;
Next, check the source code TextView and find the following code in line 509:
=;
This code is used to obtain the color. It can be found that the value of com. android. internal. R. styleable. TextAppearance_textColor is used. Check the style. xml file and find the following code:
            ?android:attr/textAppearanceSmall
Widget. TextView is the value of TextViewStyle under Theme. Then we can see that android: textAppearance is mentioned in TextView source code. Next, check :? Android: attr/textAppearanceSmall: What is the value defined in Theme.
@android:style/TextAppearance.Small
We can see that the value of textAppearanceSmall is @ android: style/TextAppearance. Small, and find @ android: style/TextAppearance. Small in style. xml:
            14sp        ?textColorSecondary    
What is the definition name of the color? TextColorSecondary, here we finally find the place to define the color. Each topic is clearly defined and exclusive.
@android:color/secondary_text_dark
In Theme, we finally see the code that defines the color of TextView. For example, to change the default color of TextView to #333333, use the following code:
            #333333    

 

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.