1、Android系统默认支持三种字体,分别为:“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>
<!-- 这里没有设定字体,我们将在Java代码中设定 --> <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创建Typeface对象
Typeface typeFace = Typeface.createFromAsset(getAssets(),"fonts/DroidSansThai.ttf");
// 应用字体
textView.setTypeface(typeFace);

如果想对整个界面的所有控件都应用自定义字体,可以:

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);  
           }  
       }  
    
    }  
}  

Android 中使用自定义字体的方法的更多相关文章

  1. Android中制作自定义dialog对话框的实例

    http://www.jb51.net/article/83319.htm   这篇文章主要介绍了Android中制作自定义dialog对话框的实例分享,安卓自带的Dialog显然不够用,因而我们要继 ...

  2. android中获取root权限的方法以及原理(转)

    一. 概述 本文介绍了android中获取root权限的方法以及原理,让大家对android 玩家中常说的“越狱”有一个更深层次的认识. 二. Root 的介绍 1. Root 的目的 可以让我们拥有 ...

  3. Android中集成第三方库的方法和问题

    Android中集成第三方库的方法和问题 声明: 1. 本文參考了网上同学们的现有成果,在此表示感谢,參考资料在文后有链接. 2. 本文的重点在第三部分,是在开发中遇到的问题及解决的方法.第一,第二部 ...

  4. Android中获取文件路径的方法总结及对照

    最近在写文件存贮,Android中获取文件路径的方法比较多,所以自己也很混乱.找了好几篇博客,发现了以下的路径归纳,记录一下,以备不时之需 Environment.getDataDirectory() ...

  5. Android Studio设置自定义字体

    Android Studio设置自定义字体 (1)进入设置页面,File->Settings (2)自定义字体Editor->Colors&Fonts->Font (3)点击 ...

  6. WebFont技术使用之如何在app中使用自定义字体

    参考 H5自定义字体解决方法(mark) 移动Web字体的使用 [原]移动web页面使用字体的思考 CSS @font-face规则 引用外部服务器字体

  7. Android中的自定义Adapter(继承自BaseAdapter)——与系统Adapter的调用方法一致——含ViewHolder显示效率的优化(转)

    Android中很多地方使用的是适配器(Adapter)机制,那我们就要好好把这个Adapter利用起来,并且用出自己的特色,来符合我们自行设计的需要喽~~~ 下面先上一个例子,是使用ViewHold ...

  8. (原创)如何在spannableString中使用自定义字体

    最近在做车联网的产品,主打的是语音交互和导航功能,UI给的导航界面可真是够酷炫的.但麻烦的事情也来了,里面的一句话居然用到了三种字体.界面如图所示: 从图中可以看出 500m左前方行驶 居然使用了三种 ...

  9. Android中的onActivityResult和setResult方法的使用

    如果你想在Activity中得到新打开Activity关闭后返回的数据,你需要使用系统提供的startActivityForResult(Intent intent,int requestCode)方 ...

随机推荐

  1. 用Ogre实现《天龙八部》场景中水面(TerrainLiquid)详解

    本文主要讲的是<天龙八部>游戏中水面(TerrainLiquid)的具体实现,使用C++,Ogre1.6. 天龙的水面做的比较简单,虽然没有倒影,但动态纹理+深度图做出的效果还行,看着不是 ...

  2. 重拾java系列一java基础(4)

    本章主要回顾一些类的相关知识: (1)static: static 静态的: 属于类的资源, 使用类名访问.  静态属性: 只有一份的变量  静态方法: 是属于类方法, 可以使用类名直接访问. 静态方 ...

  3. To and Fro

    Description Mo and Larry have devised a way of encrypting messages. They first decide secretly on th ...

  4. The Blocks Problem

    Description Many areas of Computer Science use simple, abstract domains for both analytical and empi ...

  5. 如何用JS获取ASP.net中的textbox的值 js获不到text值

    <tr>                        <td class="table_body" style="width: 10%" a ...

  6. CodeForces 416D (贪心)

    Problem Population Size 题目大意 给一个长度为n的序列,由 -1 和正整数组成,-1表示任意的正整数. 将序列分成若干段,使得任意段都是等差数列,求最少段数. 解题分析 可以发 ...

  7. PHP 安全

    作为PHP程序员,特别是新手,对于互联网的险恶总是知道的太少,对于外部的入侵有很多时候是素手无策的,他们根本不知道黑客是如何入侵的.提交入侵.上传漏洞.sql 注入.跨脚本攻击等等.作为最基本的防范你 ...

  8. 12-1 上午mysql 基本语句

    create table test( code varchar(20) primary key, name varchar(20)); 关键字primary key 主键非空 not nullfore ...

  9. nginx的压力测试

    #-----------http_load讲解------------------------------------#   Web服务器压力测试工具常见的有http_load.webbench.ab ...

  10. setInterval 函数传参(方法一)

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...