Paste the code of an activity to demonstrate the usage of typeface.
Package cn.com. chenzheng_java; </P> <p> Import android. app. activity; <br/> Import android. graphics. typeface; <br/> Import android. OS. bundle; <br/> Import android. widget. textview; <br/>/** <br/> * @ description about font Settings <br/> * @ author chenzheng_java <br/> */<br/> public class fontfaceactivity extends activity {</P> <p> @ override <br/> protected void oncreate (bundle savedinstancestate) {<br/> super. oncr Eate (savedinstancestate); <br/> setcontentview (R. layout. fontface); </P> <p> textview = (textview) findviewbyid (R. id. textview_fontface); <br/>/** <br/> * settypeface (typeface TF) set the font <br/> * settypeface (typeface TF, int style) set the font, however, there are still some gradient or bold settings, and you can use the style to set <br/> */<br/>/* textview. settypeface (typeface. default_bold, typeface. italic); <br/> textview. settext ("Chinese! "); */</P> <p> typeface TF = typeface. createfromasset (getassets (), "Font/Arial. TTF "); <br/> textview. settypeface (TF, typeface. bold_italic); <br/> textview. settext ("Chinese! Set the font! "); </P> <p >}< br/>
-------------------------------------------------------------------------------
The android. Graphics. typeface class specifies the style attribute of the font. This class helps us set the specific attributes of the font when drawing the font, such as like textsize, textskewx, and textscalex.
The methods for creating typeface are as follows:
The createfromasset () method is used in our code. This method can obtain the TTF font file in the asset folder in our application and return a typeface object based on the file.
It must be noted that the path does not start with "/". It has been plagued for a long time during my testing! If the system does not use our font, it will automatically use the default font instead.
Here the system provides us with some default fonts,
Because many fonts do not support bold/italic styles, we sometimes need to specify the display, which is also the role of style in many create methods.
Four values: bold/italic/normal/bold_italic
We can use the following methods to determine the style of the current typeface: