如何改变文本/字体设置在一个Android TextView?

例如,如何使文本加粗?


当前回答

如果你在画它,那么这个就可以做到:

TextPaint.setFlags(Paint.FAKE_BOLD_TEXT_FLAG);

其他回答

从XML中,您可以将textStyle设置为粗体,如下所示

<TextView
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:text="Bold text"
   android:textStyle="bold"/>

您可以像下面这样通过编程方式将TextView设置为粗体

textview.setTypeface(Typeface.DEFAULT_BOLD);

在.xml文件中,设置

android:textStyle="bold" 

将文本类型设置为粗体。

你可以这样做

ty.setTypeface(Typeface.createFromAsset(ctx.getAssets(), "fonts/magistral.ttf"), Typeface.BOLD);

如果你在画它,那么这个就可以做到:

TextPaint.setFlags(Paint.FAKE_BOLD_TEXT_FLAG);

设置属性

android:textStyle="bold"