Android development dynamically sets the style and thickness of the font

Source: Internet
Author: User

There are usually two types of font settings:

1: Set directly in XML

Android:textstyle= "Bold"  android:typeface

2: Set in the form of Java code

Use the typeface class in the Android SDK to define fonts, which can be set by common font type names, such as setting Italic:

TextView Quehuo = (TextView) Findviewbyid (R.id.quehuo);//Set style TextView for the fonts displayed in Quehuo.settypeface (typeface.sans_ SERIF, typeface.italic);

commonly used font type name there:

* Typeface.default//General font type

* Typeface.default_bold//blackbody font type

* Typeface.monospace//equal-width font type

* Typeface.sans_serif//sans SERIF font type

* Typeface.serif//serif Font type

In addition to font type settings, you can also set font styles for font types, such as bold:

commonly used font style name also:

* Typeface.bold//Bold

* Typeface.bold_italic//Bold Italic

* Typeface.italic//Italic

* Typeface.normal//General

TextView Quehuo = (TextView) Findviewbyid (R.id.quehuo); // Sets the style Quehuo.settypeface (Typeface.sans_serif, Typeface.italic) for the font displayed for TextView ;

There are two types of settypeface in the above code:

1. Set font type only: Settypeface (Typeface tf): The meaning of the parameter is to set the font type

2, Settypeface (Typeface tf,int style): The first parameter means to set the font type, the second parameter means to set the font style.

The style and thickness of the font that the Android development dynamically sets

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.