Android uses a custom font method _android

Source: Internet
Author: User

The examples in this article describe how Android uses custom fonts. Share to everyone for your reference, specific as follows:

First, the question:

As an Android beginner, in doing a game, the title of the game I use is textview,android only provide italic bold, but the font set into italics game interface will be better, how to achieve.

Second, the solution:

Using custom Fonts
android typeface use TTF font file to set fonts

We can put the TTF font file in the program and use typeface to set the font in the program.

The first step is to create a new fonts directory under the assets directory and put TTF font files here.

In the second step, the program calls:

Assetmanager mgr=getassets ()//Get Assetmanager
typeface Tf=typeface.createfromasset (Mgr, "Fonts/ttf.ttf"); Get typeface
Tv.settypeface (TF) based on path;//Set Font

Use android:textstyle= "Bold" in an XML file to set English bold, but you cannot set Chinese to bold.
The way to set Chinese in bold is to:

TextView TV = (TextView) Findviewbyid (r.id.textview01);
Tv.getpaint (). Setfakeboldtext (true);
Chinese imitation "bold"--use textpaint faux bold to set Setfakeboldtext to true.

I hope this article will help you with the Android program.

Related Article

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.