android TextView中设置字体为粗体

英文设置Bold Font

  • 方法1: 直接在xml布局文件中设置

布局文件:

1
android:textStyle="bold"

字符串资源文件:

1
<string name="title"><b>Page1</b></string>
  • 方法2: 在代码中直接用html的方式设置
1
textView.setText("Plain, <b>bold</b>, <i>italic</i>, <b><i>bold-italic</i></b>")

中文设置Bold Font

  • 方法:在代码中设置TextViewPaint
1
2
3
TextView textView = (TextView)findViewById(R.id.textView);   
TextPaint tp = tv.getPaint();
tp.setFakeBoldText(true);