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

Source: Internet
Author: User

1.using the Font library(Use of custom fonts): Of course, if the font library and the phone is not compatible with the acquisition of what, perhaps your Chinese is invalid

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

(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: If your font library is too large (XM), you'll throw java.lang.RuntimeException:native typeface cannot be made

Exception, of course, throw this exception is not necessarily the font library large.

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, run FontSubsetGUI.exe
(b) Fill in the data
The source font is your current font package to be split
The new font is the font you want to split.
Char list can choose the font package you are currently splitting
Encodeing selected Utf-8
Click Process

(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) Usage of android:fontfamily (with a higher version 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
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 is the same as Android:typeface

Related properties: Normal, sans, serif, monospace
Reference Links:
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. There is no effect in this way

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

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

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.