Android (Java) Learning note 100:android developing font changes

Source: Internet
Author: User

First of all, if the Android internal fonts are not the fonts we need, then we need to import the font files into the Android development project, we will explain in detail in the afternoon:

1. We first analyze that I want the font of the text in the TextView control is: Chinese in italics , we found that this is not available within the Android system, so we have to import the italic file ourselves. TTF

We put the font file of Chinese italics into the assets folder, create a new Fonts folder to store Droidsansfallback.ttf files, such as:

And then how to call this font in the program:

1 protected voidonCreate (Bundle savedinstancestate) {2         Super. OnCreate (savedinstancestate);3 Setcontentview (r.layout.activity_main);4         Assetmanager mgr = Getassets (); 5          Typeface tf = Typeface.createfromasset (Mgr, "Fonts/droidsansfallback.ttf"); 6         7TextView Sentence1 =(TextView) Findviewbyid (r.id.textview1);8TextView Sentence2 =(TextView) Findviewbyid (R.ID.TEXTVIEW2);9         Ten Sentence1.settypeface (TF); One Sentence2.settypeface (TF); A}

2. The specific steps can be summarized as follows:

We can put the TTF font file in the program and use typeface to set the font in the program.
The first step is to create a new fonts directory under the assets directory and place the TTF font file here.
In the second step, the program calls:
Assetmanager mgr=getassets ();//Get Assetmanager
Typeface Tf=typeface.createfromasset (Mgr, "Fonts/ttf.ttf");//Typeface by Path
Tv.settypeface (TF);//Set Font

Android (Java) Learning note 100:android developing font changes

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.