在Android中,加载外部字体是非常容易的!

步骤如下:

1. 创建新的Android工程;

2. 在工程下的assets文件夹下新建名字为fonts的文件夹(名字可以任意选取),把所有的外部字体文件都放在这里面;如下图所示:

3. 编辑main.xml,代码如下:

main.xml<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="fill_parent"    android:layout_height="fill_parent"    android:orientation="vertical"    android:background="#222222" >     <TextView        android:id="@+id/ghost"        android:layout_width="fill_parent"        android:layout_height="fill_parent"        android:textSize="70dip"        android:gravity="center"        android:textColor="#ef0000"        android:layout_marginTop="50dip"        android:text="ghost" /> </LinearLayout>

5.编辑Activity代码,代码如下:

AndroidExternalFontsActivity.javapackage com.example.androidhive; import android.app.Activity;import android.graphics.Typeface;import android.os.Bundle;import android.widget.TextView; public class AndroidExternalFontsActivity extends Activity {    @Override    public void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.main);         // Font path        String fontPath = "fonts/Face Your Fears.ttf";         // text view label        TextView txtGhost = (TextView) findViewById(R.id.ghost);         // Loading Font Face        Typeface tf = Typeface.createFromAsset(getAssets(), fontPath);         // Applying font        txtGhost.setTypeface(tf);    }}

6.效果图:

更多相关文章

  1. Android(安卓)利用JNI调用Android(安卓)Java代码函数
  2. Android高手进阶教程(七)之----Android(安卓)中Preferences的使
  3. Android浮动窗口实现原理及代码实例
  4. Android(安卓)的实现TextView中文字链接的4种方法
  5. Android(安卓)- 文件读写操作 总结
  6. 获取Android的Java源代码并在Eclipse中关联查看的最新方法
  7. 访问Android内部RIL接口(一)
  8. Android与HTML+JS交互入门
  9. android app请求获取root权限

随机推荐

  1. 关于结果保存的10篇文章推荐
  2. 布局文件如何使用?总结布局文件实例用法
  3. 关于XMLHTTP对象的详细介绍
  4. 关于xml的作用的详细介绍
  5. 通过XSLT将xml转换为html的代码示例
  6. 带你了解什么是RSS
  7. 关于XML文档类型的详细介绍
  8. 在IE下字符串与XML转换产生BUG的解决方案
  9. XML DOM对象方法的实例解析
  10. 调用API生成RSS资源文件的实例详解