Android development-text design, Android development text

Source: Internet
Author: User

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);

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.