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

例如,如何使文本加粗?


当前回答

在我的情况下,通过string.xml通过html标签传递值..

<string name="your_string_tag"> <b> your_text </b></string> .

其他回答

在使用自定义字体,但没有粗体字体的情况下,可以使用:

myTextView.setText(Html.fromHtml("<b>" + myText + "</b>");

从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);
editText.setTypeface(Typeface.createFromAsset(getAssets(), ttfFilePath));
etitText.setTypeface(et.getTypeface(), Typeface.BOLD);

将字体和样式都设置为粗体。

假设你是Android Studio的新手, 你可以在设计视图XML中使用

android:textStyle="bold"          //to make text bold
android:textStyle="italic"        //to make text italic
android:textStyle="bold|italic"   //to make text bold & italic

你可以这样做

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