欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

解析Android中使用自定義字體的實(shí)現(xiàn)方法

 更新時(shí)間:2013年05月10日 09:24:39   作者:  
本篇文章是對(duì)在Android中使用自定義字體的方法進(jìn)行了詳細(xì)的分析介紹。需要的朋友參考下

1、Android系統(tǒng)默認(rèn)支持三種字體,分別為:“sans”, “serif”, “monospace

2、在Android中可以引入其他字體 。

復(fù)制代碼 代碼如下:

<?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:layout_marginRight="4px"
            Android:text="sans:"
            Android:textSize="20sp" >
        </TextView>
        <!-- 使用默認(rèn)的sans字體 -->

        <TextView
            Android:id="@+id/sans"
            Android:text="Hello,World"
            Android:textSize="20sp"
            Android:typeface="sans" >
        </TextView>
    </TableRow>

    <TableRow>

        <TextView
            Android:layout_marginRight="4px"
            Android:text="serif:"
            Android:textSize="20sp" >
        </TextView>
        <!-- 使用默認(rèn)的serifs字體 -->

        <TextView
            Android:id="@+id/serif"
            Android:text="Hello,World"
            Android:textSize="20sp"
            Android:typeface="serif" >
        </TextView>
    </TableRow>

    <TableRow>

        <TextView
            Android:layout_marginRight="4px"
            Android:text="monospace:"
            Android:textSize="20sp" >
        </TextView>
        <!-- 使用默認(rèn)的monospace字體 -->

        <TextView
            Android:id="@+id/monospace"
            Android:text="Hello,World"
            Android:textSize="20sp"
            Android:typeface="monospace" >
        </TextView>
    </TableRow>
    <!-- 這里沒(méi)有設(shè)定字體,我們將在Java代碼中設(shè)定 -->

    <TableRow>

        <TextView
            Android:layout_marginRight="4px"
            Android:text="custom:"
            Android:textSize="20sp" >
        </TextView>

        <TextView
            Android:id="@+id/custom"
            Android:text="Hello,World"
            Android:textSize="20sp" >
        </TextView>
    </TableRow>

</TableLayout>


復(fù)制代碼 代碼如下:

// 得到TextView控件對(duì)象
TextView textView = (TextView) findViewById(R.id.custom);
// 將字體文件保存在assets/fonts/目錄下,www.linuxidc.com創(chuàng)建Typeface對(duì)象
Typeface typeFace = Typeface.createFromAsset(getAssets(),"fonts/DroidSansThai.ttf");
// 應(yīng)用字體
textView.setTypeface(typeFace);

如果想對(duì)整個(gè)界面的所有控件都應(yīng)用自定義字體,可以:
復(fù)制代碼 代碼如下:

package arui.blog.csdn.net;  

import android.app.Activity;  
import android.graphics.Typeface;  
import android.view.View;  
import android.view.ViewGroup;  
import android.widget.Button;  
import android.widget.EditText;  
import android.widget.TextView;  

public class FontManager {  

    public static void changeFonts(ViewGroup root, Activity act) {  

       Typeface tf = Typeface.createFromAsset(act.getAssets(),  
              "fonts/xxx.ttf");  

       for (int i = 0; i < root.getChildCount(); i++) {  
           View v = root.getChildAt(i);  
           if (v instanceof TextView) {  
              ((TextView) v).setTypeface(tf);  
           } else if (v instanceof Button) {  
              ((Button) v).setTypeface(tf);  
           } else if (v instanceof EditText) {  
              ((EditText) v).setTypeface(tf);  
           } else if (v instanceof ViewGroup) {  
              changeFonts((ViewGroup) v, act);  
           }  
       }  

    }  

相關(guān)文章

  • Android 得到連接熱點(diǎn)的ip的方法

    Android 得到連接熱點(diǎn)的ip的方法

    這篇文章主要介紹了Android 得到連接熱點(diǎn)的ip的方法 ,需要的朋友可以參考下
    2018-01-01
  • Android實(shí)現(xiàn)從底部彈出的Dialog的實(shí)例代碼

    Android實(shí)現(xiàn)從底部彈出的Dialog的實(shí)例代碼

    這篇文章主要介紹了Android實(shí)現(xiàn)從底部彈出的Dialog的實(shí)例代碼,非常不錯(cuò),具有參考借鑒價(jià)值 ,需要的朋友可以參考下
    2018-04-04
  • Android  AbsoluteLayout和RelativeLayout布局詳解

    Android AbsoluteLayout和RelativeLayout布局詳解

    本文主要講解Android AbsoluteLayout和RelativeLayout布局,這里整理了相關(guān)資料,并附示例代碼和效果圖,有興趣的小伙伴可以參考下
    2016-08-08
  • 使用IntelliJ IDEA 配置安卓(Android)開(kāi)發(fā)環(huán)境的教程詳解(新手必看)

    使用IntelliJ IDEA 配置安卓(Android)開(kāi)發(fā)環(huán)境的教程詳解(新手必看)

    這篇文章主要介紹了使用IntelliJ IDEA 配置安卓(Android)開(kāi)發(fā)環(huán)境的教程詳解(新手必看),本文通過(guò)圖文并茂的形式給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2020-09-09
  • 淺談Okhttp去除請(qǐng)求頭user-agent

    淺談Okhttp去除請(qǐng)求頭user-agent

    本篇文章主要介紹了淺談Okhttp去除請(qǐng)求頭user-agent,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2017-12-12
  • SimpleCommand實(shí)現(xiàn)圖片下載(二)

    SimpleCommand實(shí)現(xiàn)圖片下載(二)

    這篇文章主要為大家詳細(xì)介紹了SimpleCommand實(shí)現(xiàn)圖片下載,并顯示到ImageView控件上,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-10-10
  • android車(chē)牌識(shí)別系統(tǒng)EasyPR使用詳解

    android車(chē)牌識(shí)別系統(tǒng)EasyPR使用詳解

    這篇文章主要為大家詳細(xì)介紹了android車(chē)牌識(shí)別系統(tǒng)EasyPR使用,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2018-12-12
  • Android振動(dòng)器使用方法詳解

    Android振動(dòng)器使用方法詳解

    這篇文章主要為大家詳細(xì)介紹了Android振動(dòng)器使用方法,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2021-08-08
  • 最新評(píng)論