Android字體設置及Roboto字體使用方法
本文實例講述了Android字體設置及Roboto字體使用方法。分享給大家供大家參考。具體分析如下:
一、自定義字體
1.android Typeface使用TTF字體文件設置字體
我們可以在程序中放入ttf字體文件,在程序中使用Typeface設置字體。
第一步,在assets目錄下新建fonts目錄,把ttf字體文件放到這。
第二步,程序中調(diào)用:
Typeface tf=Typeface.createFromAsset(mgr, "fonts/ttf.ttf");//根據(jù)路徑得到Typeface
tv=findViewById(R.id.textview);
tv.setTypeface(tf);//設置字體
2.在xml文件中使用android:textStyle=”bold” 可以將英文設置成粗體, 但是不能將中文設置成粗體,
將中文設置成粗體的方法是:
tv.getPaint().setFakeBoldText(true);//中文仿“粗體”--使用TextPaint的仿“粗體”設置setFakeBoldText為true。
注意:部分字體中文無效,雖然不會報錯,但是對中文無效。
二、使用RoBoto
自從Android4.0后默認字體就使用了Roboto,下面介紹一下使用方法:
android:fontFamily="sans-serif-light" // roboto light
android:fontFamily="sans-serif-condensed" // roboto condensed
android:fontFamily="sans-serif-thin" // roboto thin (android 4.2)
//in combination with
android:textStyle="normal|bold|italic"
可用的參數(shù)如下:
Regular
Italic
Bold
Bold-italic
Light
Light-italic
Thin
Thin-italic
Condensed regular
Condensed italic
Condensed bold
Condensed bold-italic
希望本文所述對大家的Android程序設計有所幫助。
- android TextView設置中文字體加粗實現(xiàn)方法
- Android開發(fā)筆記 改變字體顏色的三種方法
- android 設置控件的顏色字體的方法
- Android系統(tǒng)更改狀態(tài)欄字體顏色
- android根據(jù)分辨率自動調(diào)整字體大小的實例代碼
- Android編程實現(xiàn)自動調(diào)整TextView字體大小以適應文字長度的方法
- android 字體顏色選擇器(ColorPicker)介紹
- Android TextView字體顏色設置方法小結(jié)
- Android Dialog 設置字體大小的具體方法
- Android自定義控件打造閃閃發(fā)光字體
相關文章
Android基礎控件(EditView、SeekBar等)的使用方法
這篇文章主要介紹了Android基礎控件的屬性及使用方法,介紹了基礎控件有TextView、ImageView、Button、EditView等,感興趣的小伙伴們可以參考一下2016-03-03