如何在TextView里面设置字体粗

一,在代码中动态设置,有两种方法

1,通过获取TextView的画笔设置,不建议使用该方法,加粗效果不明显

  TextView textView = new TextView(getContext());

  TextPaint paint = textView.getPaint();

  paint.setFakeBoldText(true);

2,通过setTypeface设置,推荐该方式

  TextView textView = new TextView(getContext());

  textView.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));

二,在布局中静态设置,比较简单直接

<TextView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:textStyle="bold"/>

猜你喜欢

转载自blog.csdn.net/I52013149/article/details/84432512