Android支持自定义的ttf字体Demo



一、

所谓无图无真相,先看效果图:

二 、代码:

 package yc.android.fonts;

    import android.app.Activity;
    import android.graphics.Typeface;
    import android.os.Bundle;
    import android.widget.TextView;

    public class Y_fonts extends Activity {
            /** Called when the activity is first created. */
            @Override
            public void onCreate(Bundle savedInstanceState) {
                    super.onCreate(savedInstanceState);
                    setContentView(R.layout.main);
                    /*
* 必须事先在assets底下创建一fonts文件夹 并放入要使用的字体文件(.ttf)
* 并提供相对路径给creatFromAsset()来创建Typeface对象
*/
                    Typeface fontFace = Typeface.createFromAsset(getAssets(),
                                    "fonts/STXINGKA.TTF");
                    // 字体文件必须是true type font的格式(ttf);
// 当使用外部字体却又发现字体没有变化的时候(以 Droid Sans代替),通常是因为
// 这个字体android没有支持,而非你的程序发生了错误

                    TextView text = (TextView) findViewById(R.id.ttf);
                    text.setTypeface(fontFace);
            }
    }


转自:http://www.cnblogs.com/yc-755909659/archive/2012/04/01/2429363.html

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章