如何改变文本/字体设置在一个Android TextView?
例如,如何使文本加粗?
如何改变文本/字体设置在一个Android TextView?
例如,如何使文本加粗?
当前回答
通过XML:
android:textStyle="bold"
通过Java:
//Let's say you have a textview
textview.setTypeface(null, Typeface.BOLD);
其他回答
如果你在画它,那么这个就可以做到:
TextPaint.setFlags(Paint.FAKE_BOLD_TEXT_FLAG);
设置属性
android:textStyle="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));
这是解决方案
TextView questionValue = (TextView) findViewById(R.layout.TextView01);
questionValue.setTypeface(null, Typeface.BOLD);
在.xml文件中,设置
android:textStyle="bold"
将文本类型设置为粗体。