Android 设置TextView字体加粗

作者: cnbzlj 发布时间: 2019-09-20 浏览: 5045 次 编辑

今天,简单讲讲Android里如何设置TextView字体加粗。

不废话了,用过多次,还是没记住。直接上代码。

1.布局文件中这样设置即可:

XML/HTML代码

android:textStyle="bold"

2,java代码中字体加粗:

TextView textView= new TextView(context);//或从xml导入 
TextPaint paint = textView.getPaint();
paint.setFakeBoldText(true);

或者

// 方式一
textView.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));
// 方式二
textView.setTypeface(Typeface.DEFAULT_BOLD);

Android 设置TextView字体加粗就讲完了。

就这么简单。