如何改变文本/字体设置在一个Android TextView?
例如,如何使文本加粗?
如何改变文本/字体设置在一个Android TextView?
例如,如何使文本加粗?
当前回答
从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);
其他回答
假设你是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
设置属性
android:textStyle="bold"
在Kotlin中,我们可以在一行中完成
TEXT_VIEW_ID.typeface = Typeface.defaultFromStyle(Typeface.BOLD)
editText.setTypeface(Typeface.createFromAsset(getAssets(), ttfFilePath));
etitText.setTypeface(et.getTypeface(), Typeface.BOLD);
将字体和样式都设置为粗体。
4种方法使Android TextView粗体-完整的答案在这里。
Using android:textStyle attribute <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="TEXTVIEW 1" android:textStyle="bold" /> Use bold|italic for bold and italic. using setTypeface() method textview2.setTypeface(null, Typeface.BOLD); textview2.setText("TEXTVIEW 2"); HtmlCompat.fromHtml() method, Html.fromHtml() was deprecated in API level 24. String html="This is <b>TEXTVIEW 3</b>"; textview3.setText(HtmlCompat.fromHtml(html,Typeface.BOLD));