Android字體Typeface設置

轉自: 點擊打開鏈接


Android字體Typeface設置

 
   

Android系統默認支持三種字體,分別爲:sansserifmonospace",除此之外還可以使用其他字體文件(*.ttf)

方法一:XML中使用android默認字體


       
                   Android:text="Hello,World"
                   Android:typeface="sans"
                   Android:textSize="20sp" />


       
                   Android:text="Hello,World"
                   Android:typeface="serif"
                   Android:textSize="20sp" />


       
                   Android:text="Hello,World"
                   Android:typeface="monospace"
                   Android:textSize="20sp" />

方法Android中可以引入其他字體,首先要將字體文件保存在assets/fonts/目錄下

1.  


                   Android:text="Hello,World"
                    Android:textSize="20sp" />

2.  java程序中引入其他字體關鍵代碼

  //得到TextView控件對象
        TextView textView =(TextView)findViewById(R.id.custom);

  //將字體文件保存在assets/fonts/目錄下,創建Typeface對象

  Typeface typeFace =Typeface.createFromAsset(getAssets(),"fonts/HandmadeTypewriter.ttf");

  //使用字體

  textView.setTypeface(typeFace);

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