我在xml中定义了一个textview,我按照下面的方法设置了Typeface
textView.setTypeface(APP_FONT_REGULAR); // 在 assests 中自定义字体 (.ttf file).
在xml中设置了 android:textStyle="bold"
但是为什么没有变成粗体字?
如何给字体设置粗体?
当调用 setTypeface() 你可以设置外观:
textView.setTypeface(APP_FONT_REGULAR, Typeface.BOLD);
看TextView的setTypeface方法中有解释
Sets the typeface and style in which the text should be displayed. Note that not all Typeface families actually have bold and italic variants, so you may need to use setTypeface(Typeface, int) to get the appearance that you actually want.
应该是你那字体没有粗体的样式,所以得用setTypeface(Typeface, int),即楼上的方法解决
代码中设置了setTypeface后会覆盖xml中的字体设置,可以调用textView.setTypeface(APP_FONT_REGULAR, Typeface.BOLD);