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