起因:
因爲產品對字體加粗效果不滿意,覺得沒有別人家的粗,所以呢,作者在網上查找了些資料(ps:就幾句代碼),整理了一下,放出來,給需要的同道中人使用:
效果,老規矩,先上圖:
由圖可知,就三種加粗效果(第一行是默認的大小),然後慢慢變粗的,字體大小都一樣哦。
下面貼代碼啦:
java
代碼
//第二行效果
tv1.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));
//第三行效果
tv2.getPaint().setFakeBoldText(true);
//第四行效果
tv3.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));
tv3.getPaint().setFakeBoldText(true);
xml代碼也安排上吧:
<TextView
android:id="@+id/tv_0"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="秋之殤"
android:textSize="20sp" />
<TextView
android:id="@+id/tv_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:text="秋之殤"
android:textSize="20sp" />
<TextView
android:id="@+id/tv_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:text="秋之殤"
android:textSize="20sp" />
<TextView
android:id="@+id/tv_3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:text="秋之殤"
android:textSize="20sp" />
好了一目瞭然,有用的小夥伴麻煩點個贊哈!