How to set up Android Chinese fonts and how to use them

Source: Internet
Author: User

Android TextView font color and other styles specific explanation connection: http://blog.csdn.net/pcaxb/article/details/47341249

1. Use the Font library (your own definition of the use of the font): Of course, if the font library and the phone is not compatible with the acquisition of what, maybe your Chinese is invalid

(1) In Assets new folder fonts, the TTF font library to the folder

(2) using the code

TextView View1 = (TextView) Findviewbyid (R.ID.TV1); Typeface TF1 = Typeface.createfromasset (Getassets (), "Fonts/droidserif-bold.ttf");
View1.settypeface (TF1);

(3) Problem and resolution of using font Library

Question: Assuming your font library is too large (XM), you'll throw java.lang.RuntimeException:native typeface cannot be made

Abnormal. Of course, throwing this exception is not necessarily a large font library.

Solve:

Software to use
(a) Fontcreator Font Browsing Software
(b) Fontsubset Large-font library of small font software
Tool: http://download.csdn.net/detail/pcaxb/8972239

Operation using

(a) Open Fontsubset, execute FontSubsetGUI.exe
(b) Fill in the data
The source font is your current font package to be cut
The new font is the font you want to cut.
Char list to select the font package you are currently cutting
Encodeing selected Utf-8

Click Process

Font library download link (here The font library is I compressed with fontsubset, very small): http://download.csdn.net/detail/pcaxb/8974239


(4) Android Font System library (learn)

Android System Fonts (/system/fonts):
Androidclock.ttf
Androidclock_highlight.ttf
Androidclock_solid.ttf
Androidemoji.ttf
Clockopia.ttf
Droidnaskh-regular.ttf
Droidnaskhui-regular.ttf
Droidsans-bold.ttf
Droidsans.ttf
Droidsansarmenian.ttf
Droidsansethiopic-regular.ttf
Droidsansfallback.ttf
Droidsansgeorgian.ttf
Droidsanshebrew-bold.ttf
Droidsanshebrew-regular.ttf
Droidsansmono.ttf
Droidserif-bold.ttf
Droidserif-bolditalic.ttf
Droidserif-italic.ttf
Droidserif-regular.ttf
Mtlmr3m.ttf
Roboto-bold.ttf
Roboto-bolditalic.ttf
Roboto-italic.ttf
Roboto-light.ttf
Roboto-lightitalic.ttf
Roboto-regular.ttf
Roboto-thin.ttf
Roboto-thinitalic.ttf
Robotocondensed-bold.ttf
Robotocondensed-bolditalic.ttf
Robotocondensed-italic.ttf
Robotocondensed-regular.ttf

2.set font-related properties

(1) How to use android:fontfamily (with a higher version number limit)

Related properties: Sans-serif, Sans-serif-light, sans-serif-condensed, Sans-serif-thin,

(2) android:textstyle= "Normal|bold|italic"

Related attributes Regular, Italic, Bold, Bold-italic, Light, Light-italic, Thin, thin-italic, condensed regular, condensed Italic, Condensed bold, condensed bold-italic
The android:textstyle= "bold" can be set to bold in English, but cannot be set to bold in Chinese.


Code settings

TextView TV = (TextView) Findviewbyid (r.id.textview01); Tv.getpaint (). Setfakeboldtext (true);// Set Setfakeboldtext to True using Textpaint's faux bold

(3) android:fontfamily and Android:typeface

Related properties: Normal, sans, serif, monospace
References Link:
Http://developer.android.com/reference/android/widget/TextView.html#attr_android%3atypeface
Http://stackoverflow.com/questions/12128331/how-to-change-fontfamily-of-textview-in-android

3. set the font via HTML tags ( Note that some labels are not effective ):

Button btn = (button) Findviewbyid (R.ID.BT); String Source =  "This is just a test string, test <b> boldface </b>, <i> Italic </i>, <u> underline </u>, <font Color= ' Red ' face= ' Microsoft Jas Black ' > Red word </font> display. <font face= ' young round ' size= ' 1 ' color= ' green ' > Young round Green Font </font> ' +        ' <font face= ' Arial ' > Font </font> ' +        "<font face= ' Microsoft Jas Black ' > Fonts </font>" +        "<font face= ' Arial ' >nishiwode</font> ' +        ' < Font face= ' Microsoft Black >nishiwode</font> '; Btn.settext (html.fromhtml (source));        Btn.setonfocuschangelistener (this);

4. no effect through the following way

Typeface TF1 = typeface.create ("Song Body", Typeface.normal); Typeface TF1 = typeface.create ("Sans-serif", typeface.normal);

How to set up Android Chinese fonts and how to use them

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.