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

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

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

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

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

復制代碼 代碼如下:

<?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>
        <!-- 使用默認的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>
        <!-- 使用默認的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>
        <!-- 使用默認的monospace字體 -->

        <TextView
            Android:id="@+id/monospace"
            Android:text="Hello,World"
            Android:textSize="20sp"
            Android:typeface="monospace" >
        </TextView>
    </TableRow>
    <!-- 這里沒有設(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>


復制代碼 代碼如下:

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

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

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 得到連接熱點的ip的方法

    Android 得到連接熱點的ip的方法

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

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

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

    Android AbsoluteLayout和RelativeLayout布局詳解

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

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

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

    淺談Okhttp去除請求頭user-agent

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

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

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

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

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

    Android振動器使用方法詳解

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