Enable android to support custom TTF Fonts

Source: Internet
Author: User

The so-called no picture, no truth, first look:

 

The Java code is as follows:

Package YC. Android. fonts;

Import Android. App. activity;
Import Android. Graphics. typeface;
Import Android. OS. Bundle;
Import Android. widget. textview;

Public class y_fonts extends activity {
/** Called when the activity is first created .*/
@ Override
Public void oncreate (bundle savedinstancestate ){
Super. oncreate (savedinstancestate );
Setcontentview (R. layout. Main );
/*
* You must first create a fonts folder under assets and put the font file (. TTF) to be used)
* Provide the relative path to creatfromasset () to create the typeface object.
*/
Typeface fontface = typeface. createfromasset (getassets (),
"Fonts/stxingka. TTF ");
// The font file must be in the true type font format (TTF );
// When the external font is used but the font is not changed (replaced by droid sans), it is usually because
// This font is not supported by Android, not an error in your program

Textview text = (textview) findviewbyid (R. Id. TTF );
Text. settypeface (fontface );
}
}

PS:
The font I use is a Chinese character
Because the Android system supports font files, this font file is valid in versions 2.3.3 and later, and is not supported in version 2.2.

 

Source: http://www.eoeandroid.com/thread-163834-1-1.html

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.