Android font Settings-typeface explanation

Source: Internet
Author: User

Two ways to control font settings

Common font type names are:

    • Typeface.default//General font type

    • Typeface.default_bold//Blackbody font type

    • Typeface.monospace//equal-width font type

    • Typeface.sans_serif//sans SERIF Font type

The commonly used font style names are:

    • Typeface.bold//Bold

    • Typeface.bold_italic//Coarse italic

    • Typeface.italic//Italic

    • Typeface.normal//General
      1. Set in XML.
      Use Android:typeface to set:
      Android:typeface= "Sans"
      2. In the Java program:
      EG1:
      Typeface font = typeface.create (Typeface.sans_serif, typeface.bold);
      P.settypeface (font);
      EG2:
      String familyname = "Song Body";
      Typeface font = typeface.create (familyname,typeface.bold);
      P.settypeface (font);

Using external fonts

1. First, copy the font file you want to use under the Fonts directory under assets.
2. The code is as follows:

privatevoidmySetTypeFace() {        // TODO Auto-generated method stub        //从assert中获取有资源,获得app的assert,采用getAserts(),通过给出在assert/下面的相对路径。在实际使用中,字体库可能存在于SD卡上,可以采用createFromFile()来替代createFromAsset。        "fonts/HanYi.ttf");        //title是之间定义的控件        title.setTypeface(face);    }

Android font Settings-typeface explanation

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.