先看UC瀏覽器的溫度
要實現(xiàn)17°這樣的極細(xì)的字體
自定義View
繼承TextView
衩婚,在onDraw
方法中設(shè)置畫筆粗細(xì)
TextPaint tp = new TextPaint();
tp.setAntiAlias(true);
tp.setStyle(Paint.Style.FILL_AND_STROKE);
tp.setStrokeWidth(0.1f);
setStrokeWidth
方法默認(rèn)參數(shù)是0,而且不接受負(fù)數(shù)參數(shù),也就是說,只能加粗不能變細(xì)谓晌。
Spannable
再試試Spannable
Spannable s = new SpannableString("17°29");
s.setSpan(new AbsoluteSizeSpan(30, true), 0, 3, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
s.setSpan(new AbsoluteSizeSpan(30, false), 3, 5, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
s.setSpan(new RelativeSizeSpan(2.0f), 0, 3, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
tv.setText(s);
效果也是一樣,可以改變字體大小涯贞,但是只能加粗不能變細(xì)
Thin字體
從字體本身出發(fā),嘗試尋找細(xì)細(xì)的字體
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>
我自己的嘗試
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/textview"
android:textSize="60sp"
android:layout_gravity="center_horizontal|bottom"
android:textColor="@color/colorAccent"
android:gravity="center"
android:textStyle="normal"
android:fontFamily="sans-serif-thin"
android:text="17°"/>
系統(tǒng)字體的位置
D:\Android\sdk\platforms\android-N\data\fonts
fonts.xml
里配置了字體的別名