Android font settings, Roboto font use

Source: Internet
Author: User

One, custom fonts typeface setting fonts using TTF font files

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 place the TTF font file here.
In the second step, the program calls:

[Java] view plaincopy

  1. Assetmanager mgr=getassets (); //Get Assetmanager   

  2. Typeface Tf=typeface.createfromasset (Mgr, "Fonts/ttf.ttf"); //According to the path to get typeface   

  3. Tv=findviewbyid (;

  4. Tv.settypeface (TF); //Set Font   

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

[Java] view plaincopy

  1. TextView TV = (TextView) Findviewbyid (R.ID.TEXTVIEW01);

  2. Tv.getpaint (). Setfakeboldtext (true); //Chinese Imitation "bold"--use Textpaint's faux "bold" setting Setfakeboldtext to True.   

Note: Some fonts in Chinese are not valid, although they will not be error, but not Chinese. Second, the use of Roboto

The default font has been used Roboto since Android4.0, and here's how to use it:

[Java] view plaincopy

  1. android:fontfamily= "Sans-serif"   span class= "comment" style= "Margin:0px;padding:0px;border:none;color:rgb (0,130,0); background-color:inherit;" >// roboto regular

  2. android: Fontfamily= "Sans-serif-light"    roboto light

  3. android: Fontfamily= "Sans-serif-condensed"    roboto condensed   

  4. android:fontfamily="Sans-serif-thin" //Roboto thin (Android 4.2)

  5. //in combination with   

  6. android:textstyle="Normal|bold|italic"

Available parameters:

Condensed Regular
Condensed italic
Condensed Bold
Condensed Bold-italic

Other great article articles

Android KSOAP2 call. NET Webservicejquery Tutorial (8)- Using the reverse Insert method for DOM tree operation Android Learning Note (34) using Alertdialog to create a simple dialog box Android learning Note (33) Gallery View (Gallery) features and usage Android navidgation drawer How to change the list selection in the navigation drawer ...

More about Android development articles

This article is from the "Moe It People" blog, please be sure to keep this source

Android font settings, Roboto font use

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: 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.