In addition to changing the font size, android can also change the font style. The method is very simple. You only need to copy the corresponding font to the Assets Directory edge.
The procedure is as follows:
1. after preparing the font, copy a font in Windows/fonts and paste it to the Assets Directory of the eclipse project. The Assets Directory can store any resource files, create a new fonts directory and store the copied font as needed.
2. Edit main. XML, add a textview and two buttons, and set the ID respectively.
<? XML version =" 1.0 "Encoding =" UTF-8 "?> <Linearlayout xmlns: Android =" Http://schemas.android.com/apk/res/android "Android: Orientation =" Vertical "Android: layout_width =" Fill_parent "Android: layout_height =" Fill_parent "> <Textview Android: layout_width ="Fill_parent "Android: layout_height =" Wrap_content "Android: text =" @ String/tvtext "Android: Id =" @ + ID/tvtext "/> <Button Android: layout_width =" Wrap_content "Android: Id =" @ + ID/btnchangefontstyle "Android: layout_height =" Wrap_content "Android: text =" @ String/btnchangestyle_text "> </Button> <button Android: layout_width =" Wrap_content "Android: Id ="@ + ID/btnchangefontsize "Android: layout_height =" Wrap_content "Android: text =" @ String/btnfontsize_text "> </Button> </linearlayout>
3. Edit and change the font and size accordingly.Code
Package gphone. ex03_13; import android. app. activity; import android. app. alertdialog; import android. content. dialoginterface; import android. graphics. typeface; import android. OS. bundle; import android. view. view; import android. widget. button; import android. widget. textview; public class ex03_13 extends activity {textview tvtext = NULL; button btnchangefontstyle = NULL; button btnchangefontsize = NULL;/** called when the activity is first created. * // @ override public void oncreate (bundle savedinstancestate) {super. oncreate (savedinstancestate); setcontentview (R. layout. main); tvtext = (textview) findviewbyid (R. id. tvtext); btnchangefontstyle = (button) findviewbyid (R. id. btnchangefontstyle); btnchangefontsize = (button) findviewbyid (R. id. btnchangefontsize); btnchangefontstyle. setonclicklistener (new view. onclicklistener () {@ overridepublic void onclick (view v) {// todo auto-generated method stubTvtext. settypeface (typeface. createfromasset (getassets (), "fonts/stcaiyun. TTF ")); }); Btnchangefontsize. setonclicklistener (New View. onclicklistener () {@ overridepublic void onclick (view v) {// todo auto-generated method stub Tvtext. settextsize (50 ); }});}}