Android development-text design, Android development text
Android development text Design 1. font size
Set the font size directly in the control:
Common sp for font size, because if sp is used, you can change the font size in the system settings to change the text size, while dp is not. dp is generally used to set the length and width.
Change the font size in the Code:
tv = (TextView)this.findViewById(R.id.text); tv.setTextSize(15);
The default value is sp.
Ii. Font color
Set the font color in the layout Control
android:textColor="#ff000000"
The font color code is an 8-digit hexadecimal number. The first two digits are transparency, and the last six digits are RGB color codes.
Change the font color in the code
TV = (TextView) this. findViewById (R. id. text); // obtain the text Control TV. setTextColor (0xffff00ff );
The setTextColor parameter is a hexadecimal integer.
RGB color table
3. Set font styles
Android comes with four types, but I cannot see the differences between these four types... In addition, we can download the ttf font file online to set the font we like;
To use your own font, you must first have a font file, then create an assets folder under the main folder, create a fonts folder under the assets folder, and then put the font file under this folder.
Finally, you need to set a non-system built-in font in the Code, rather than in the layout file as before;
Typeface face = Typeface.createFromAsset(this.getAssets(),"fonts/hwxk.ttf"); tv.setTypeface(face);
4. Other font settings
1. Set bold
In the layout file, set the property android: textStyle = "bold" for the font control"
Or use the code in the Code:
tv.getPaint().setFakeBoldText(true);
2. Underline
tv.getPaint().setFlags(Paint.UNDERLINE_TEXT_FLAG);
Or
tv.getPaint().setUnderlineText(true);
3. Set italics
TV. getPaint (). setTextSkewX (-0.5f); // This method parameter is float type, with a positive left oblique negative and a right oblique value. The specific value is the slope.
4. strikethrough
tv.getPaint().setStrikeThruText(true);