The use of fonts under Android programming

Source: Internet
Author: User


Take a look at the code implementation process, before the implementation of code implementation, we first look at the different font display effect , in the first picture: Simkai.ttf Simplified-italic-general, second picture: Msyh.ttf Simplified-Microsoft black-General.

1  Packagecn.sunzn.fonts;2 3 Importandroid.app.Activity;4 ImportAndroid.graphics.Typeface;5 ImportAndroid.os.Bundle;6 ImportAndroid.view.Menu;7 ImportAndroid.widget.TextView;8 9  Public classMainactivityextendsActivity {Ten  One     PrivateTextView Tv_title; A     PrivateTextView Tv_author; -     PrivateTextView tv_line1; -     PrivateTextView Tv_line2; the     PrivateTextView Tv_line3; -     PrivateTextView tv_line4; -  -      Public voidonCreate (Bundle savedinstancestate) { +         Super. OnCreate (savedinstancestate); - Setcontentview (r.layout.activity_main); +         /** A * Create the Fonts folder in the assets directory and put in the font file (**.ttf) to be used and provide a relative path to at * Createfromasset (assetmanager Mgr, String Path) to create the Typeface object, then pass - * over Textview.settypeface (Typeface tf) specifies the font for text display.  -          */ -Typeface face = Typeface.createfromasset (Getassets (), "Fonts/simfang". TTF "); -  -Tv_title =(TextView) Findviewbyid (r.id.tv_title); in Tv_title.settypeface (face); -  toTv_author =(TextView) Findviewbyid (r.id.tv_author); + Tv_author.settypeface (face); -  theTv_line1 =(TextView) Findviewbyid (r.id.tv_line1); * Tv_line1.settypeface (face); $ Panax NotoginsengTv_line2 =(TextView) Findviewbyid (r.id.tv_line2); - Tv_line2.settypeface (face); theTv_line3 =(TextView) Findviewbyid (R.ID.TV_LINE3); + Tv_line3.settypeface (face); A  theTv_line4 =(TextView) Findviewbyid (r.id.tv_line4); + Tv_line4.settypeface (face); -     } $  $      Public BooleanOncreateoptionsmenu (Menu menu) { - getmenuinflater (). Inflate (R.menu.activity_main, menu); -         return true; the     } - Wuyi}

Finally, It is also necessary to add a note: Although this is the way to achieve the results you want to display, but before using this method, developers need to consider the performance and operating environment and the style of their own APP, and then make the corresponding choice. There are several reasons for this:

    • Font file size: Because the font size is a few trillion, more than a few 10 trillion, file packaging when the *.TTF format file compression rate is very low, so it will virtually increase the volume of the APP.
    • Operating Environment considerations: If your app is oriented to a high-version runtime environment, consider using this method if the user's operating environment is Android 2.2 that needs to be discarded.
    • Application-style considerations: If your app is both oriented to a high-version runtime environment, and you use the specified font in your app, you can consider using this method; If you use a font for only a few words in your app, you'll lose the candle.

The use of fonts under Android programming

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.