先看UC浏览器的温度
![](https://i-blog.csdnimg.cn/blog_migrate/000045a7ac94f4c61cacad6a0f110b63.webp?x-image-process=image/format,png)
uc_weather.png
要实现17°这样的极细的字体
自定义View
继承TextView
,在onDraw
方法中设置画笔粗细
TextPaint tp = new TextPaint();
tp.setAntiAlias(true);
tp.setStyle(Paint.Style.FILL_AND_STROKE);
tp.setStrokeWidth(0.1f);
setStrokeWidth
方法默认参数是0,而且不接受负数参数,也就是说,只能加粗不能变细。
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);
效果也是一样,可以改变字体大小,但是只能加粗不能变细
Thin字体
从字体本身出发,尝试寻找细细的字体
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°"/>
![](https://i-blog.csdnimg.cn/blog_migrate/a8b1e1cbb2efda11ac6d2fb64ba53047.webp?x-image-process=image/format,png)
me_weather.png
系统字体的位置
D:\Android\sdk\platforms\android-N\data\fonts
fonts.xml
里配置了字体的别名
作者:wIsper
链接:http://www.jianshu.com/p/69a05f99a9ff
來源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。