一共有12種組合
Added in Android Jelly Bean (4.1) - API 16 :
Regular (default):
<item name="android:fontFamily">sans-serif</item>
<item name="android:textStyle">normal</item>
Italic:
<item name="android:fontFamily">sans-serif</item>
<item name="android:textStyle">italic</item>
Bold:
<item name="android:fontFamily">sans-serif</item>
<item name="android:textStyle">bold</item>
Bold-italic:
<item name="android:fontFamily">sans-serif</item>
<item name="android:textStyle">bold|italic</item>
Light:
<item name="android:fontFamily">sans-serif-light</item>
<item name="android:textStyle">normal</item>
Light-italic:
<item name="android:fontFamily">sans-serif-light</item>
<item name="android:textStyle">italic</item>
Thin :
<item name="android:fontFamily">sans-serif-thin</item>
<item name="android:textStyle">normal</item>
Thin-italic :
<item name="android:fontFamily">sans-serif-thin</item>
<item name="android:textStyle">italic</item>
Condensed regular:
<item name="android:fontFamily">sans-serif-condensed</item>
<item name="android:textStyle">normal</item>
Condensed italic:
<item name="android:fontFamily">sans-serif-condensed</item>
<item name="android:textStyle">italic</item>
Condensed bold:
<item name="android:fontFamily">sans-serif-condensed</item>
<item name="android:textStyle">bold</item>
Condensed bold-italic:
<item name="android:fontFamily">sans-serif-condensed</item>
<item name="android:textStyle">bold|italic</item>
Added in Android Lollipop (v5.0) - API 21 :
Medium:
<item name="android:fontFamily">sans-serif-medium</item>
<item name="android:textStyle">normal</item>
Medium-italic:
<item name="android:fontFamily">sans-serif-medium</item>
<item name="android:textStyle">italic</item>
Black:
<item name="android:fontFamily">sans-serif-black</item>
<item name="android:textStyle">italic</item>
具體樣式如下:
代碼中動(dòng)態(tài)設(shè)置
方法1 :只單純?cè)O(shè)置粗體和正常
//android中為textview動(dòng)態(tài)設(shè)置字體為粗體
TextView textView = (TextView)findViewById(R.id.textView);
textView .setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));
//設(shè)置為不加粗
textView.setTypeface(Typeface.defaultFromStyle(Typeface.NORMAL));
方法2 :同時(shí)搭配Fontfamily (此方法會(huì)覆蓋方法1)
//android中為textview動(dòng)態(tài)設(shè)置字體為粗體
TextView textView = (TextView)findViewById(R.id.textView);
//其中"sans-serif"為上面介紹的fontfamily的字符串名字交煞,
//這個(gè)最好用一個(gè)string 資源映射,便于使用
textView .setTypeface(Typeface.create("sans-serif",Typeface.BOLD));
//同理 設(shè)置為不加粗
textView.setTypeface(Typeface.create("sans-serif-thin",Typeface.NORMAL));