如何改变文本/字体设置在一个Android TextView?
例如,如何使文本加粗?
如何改变文本/字体设置在一个Android TextView?
例如,如何使文本加粗?
当前回答
这是解决方案
TextView questionValue = (TextView) findViewById(R.layout.TextView01);
questionValue.setTypeface(null, Typeface.BOLD);
其他回答
你可以这样做
ty.setTypeface(Typeface.createFromAsset(ctx.getAssets(), "fonts/magistral.ttf"), Typeface.BOLD);
在XML中
android:textStyle="bold" //only bold
android:textStyle="italic" //only italic
android:textStyle="bold|italic" //bold & italic
你只能使用特定的字体sans, serif和monospace通过xml, Java代码可以使用自定义字体
android:typeface="monospace" // or sans or serif
以编程方式(Java代码)
TextView textView = (TextView) findViewById(R.id.TextView1);
textView.setTypeface(Typeface.SANS_SERIF); //only font style
textView.setTypeface(null,Typeface.BOLD); //only text style(only bold)
textView.setTypeface(null,Typeface.BOLD_ITALIC); //only text style(bold & italic)
textView.setTypeface(Typeface.SANS_SERIF,Typeface.BOLD);
//font style & text style(only bold)
textView.setTypeface(Typeface.SANS_SERIF,Typeface.BOLD_ITALIC);
//font style & text style(bold & italic)
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));
在.xml文件中,设置
android:textStyle="bold"
将文本类型设置为粗体。
你可以简单地做以下几点:
以XML格式设置属性
android:textStyle="bold"
从程序上看,方法是:
TextView Tv = (TextView) findViewById(R.id.TextView);
Typeface boldTypeface = Typeface.defaultFromStyle(Typeface.BOLD);
Tv.setTypeface(boldTypeface);
希望这能帮到你,谢谢。