Android Custom TTF Font

Source: Internet
Author: User

Objective:

  A design manual in Android designs. There are commonly used UI icons, icon size specifications, and so on in the design manual.

Among them, there is a TTF font, previously felt useless. But when I was studying, I often saw a lot of developers using Google

The TTF font provided. I counted it. There are 19 fonts to choose from, while Android comes with only 4 options to choose from. I use

A project to test all the font effects.

Java code:

ImportAndroid.os.Bundle;Importandroid.app.Activity;ImportAndroid.graphics.Typeface;ImportAndroid.widget.TextView; Public classMainactivityextendsActivity {Private intTtf_str[] ={r.string.ttf_1, r.string.ttf_2, R.string.ttf_3, R.string.ttf_4, R.string.ttf_5, R.string.ttf_6, R.string . ttf_7, R.string.ttf_8, R.string.ttf_9, R.string.ttf_10, R.string.ttf_11, R.string.ttf_12, R.string. Ttf_13, R.string.ttf_14, R.string.ttf_15, R.string.ttf_16, R.string.ttf_17, r.string.ttf_18, R.string.ttf_19,}    ; Private intTtf_id[] ={r.id.ttf_1, r.id.ttf_2, R.id.ttf_3, R.id.ttf_4, R.id.ttf_5, R.id.ttf_6, r.id.ttf_7, R.id.ttf_8, R.id.ttf _9, R.id.ttf_10, R.id.ttf_11, R.id.ttf_12, r.id.ttf_13, r.id.ttf_14, R.id.ttf_15, R.id.ttf_16, R.id.    Ttf_17, R.id.ttf_18, r.id.ttf_19,}; @Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate);        Setcontentview (R.layout.activity_main); /** Set Custom Auto*/         for(inti = 0; I <= 18; ++i) Showttf ("fonts/" +getString (Ttf_str[i]), ttf_id[i]); }    Private voidShowttf (String Path,intID) {Typeface fontface=Typeface.createfromasset (getassets (), path); TextView text=(TextView) Findviewbyid (ID);    Text.settypeface (Fontface); }}

Note: Android Project package download. All TTF fonts are included in the project. Point here

Android Custom TTF Font

Related Article

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.