How do I load font resources in Androidstudio?

Source: Internet
Author: User

The format of the fonts in Android is always not the perfect display, and asked us to use some beautiful fonts, loading the way (like HTML font), we need to load the font to use the font is not available in Android;

First find the Assets folder in the Androidstudio, (located under Serc/main/java, and res in the same file), find the font file (*.ttf) into this folder (of course, for the sake of specification, We can set up a font folder to represent the fonts file asseets. :

After the resource has been successfully stored, the font is loaded and used through the code:

where the Context.getassets () method is used to load the assets folder, "Opensans-regular.ttf" is the relative path of the font file, the attentive classmate can see that my assert has two identical font files,

One of the following is under the Font folder, if you want to load this folder you need to use:

Typeface tf = Typeface.createfromasset (Getassets (), "Font/opensans-regular.ttf");

 
The use of this font in view is Settypeface.

How do I load font resources in Androidstudio?

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.