Android Font Related summary

Source: Internet
Author: User

1, the Android system supports three fonts by default, namely: "Sans", "serif", "monospace" system default mode (tested by default using Sans);

2. Other fonts can be introduced in Android

3. Examples are as follows:

4. layout file

Main.xml

<?xml version= "1.0" encoding= "Utf-8"?>
<tablelayout xmlns:android= "Http://schemas.android.com/apk/res/android"
Android:layout_width= "Fill_parent"
android:layout_height= "Fill_parent" >
<TableRow>
<textview android:text= "sans:"
android:layout_marginright= "4PX"
Android:textsize= "20SP" ></TextView>

<!--Use the default sans font--
<textview android:id= "@+id/sans"
android:text= "Hello,world"
android:typeface= "sans"
android:textsize= "20SP"></TextView>
</TableRow>
<TableRow>
<textview android:text= "serif:"
android:layout_marginright= "4PX"
Android:textsize= "20SP" ></TextView>

<!--Use the default serifs font--
<textview android:id= "@+id/serif"
android:text= "Hello,world"
android:typeface= "Serif"
android:textsize= "20SP"></TextView>
</TableRow>
<TableRow>
<textview android:text= "monospace:"
android:layout_marginright= "4PX"
Android:textsize= "20SP" ></TextView>

<!--Use the default monospace font--
<textview android:id= "@+id/monospace"
android:text= "Hello,world"
android:typeface= "Monospace"
android:textsize= "20SP"></TextView>
</TableRow>

<!--There is no font set, we'll set it in Java code--
<TableRow>
<textview android:text= "Custom:"
android:layout_marginright= "4PX"
android:textsize= "20SP" ></TextView>
<textview android:id= "@+id/custom"
android:text= "Hello,world"
android:textsize= "20SP"></TextView>
</TableRow>
</TableLayout>

5. Java code

Package yyl.fonts;

Import android.app.Activity;
Import Android.graphics.Typeface;
Import Android.os.Bundle;
Import Android.widget.TextView;

public class Fontsactivity extends activity {
   /** called when the activity is first created. */
    @Override
    public void onCreate (Bundle savedinstancestate) {
         super.oncreate (savedinstancestate);
        Setcontentview (R.layout.main);
       //Get TextView Control object
        TextView TextView = (TextView) Findviewbyid (r.id.custom);

Save the font file in the assets/fonts/directory and create the typeface object
Typeface Typeface = Typeface.createfromasset (Getassets (), "Fonts/handmadetypewriter.ttf");

Apply Font
Textview.settypeface (TypeFace);
}
}

Android TextView set Chinese font bold implementation method

English setting bold can be set in XML:

The code is as follows:
<span style= "font-size:18px" >android:textstyle= "bold" </SPAN>


English can also be directly in the string file directly fill in this way:

The code is as follows:
<string name= "Styled_text" >plain, <b>bold</b>, <i>italic</i>, <b><i> Bold-italic</i></b></string>


B code Bold, I stands for tilt
The Chinese setting is bold and you need to get the current TextView in your code to set it up:

The code is as follows:
TextView TV = (TextView) Findviewbyid (r.id.tv);
Textpaint TP = Tv.getpaint ();
Tp.setfakeboldtext (TRUE);

Android Font Related summary

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.