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