android:textStyle="bold" //这个是xml里面设置,但是java中并没有TextVew.setBold()的方法
方法一:
java代码如下:
private void setTextViewBoldEffect(TextView tv) {
TextPaint tp = new TextPaint();
tp.setFakeBoldText(true);
tv.setPaintFlags(tv.getPaintFlags() | Paint.FAKE_BOLD_TEXT_FLAG);
}
//调用
private TextView tvv;
tvv = findViewById(R.id.my_textView);
setTextViewBoldEffect(tvv);
原理之类的在链接里
方法二:在values里面新建style,在java里面使用setTextApparence()方法调用
<style name="my_tv_bold_style">
<item name="android:textStyle">bold</item>
</style>
AppCompatTextView tvvv = findViewById(R.id.my_textView);
tvvv.setTextAppearance(R.style.my_tv_bold_style);