Messy Android font-related class typeface

Source: Internet
Author: User

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:

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.