如何设置TextView风格(粗体或斜体)在Java和不使用XML布局?
换句话说,我需要用Java编写android:textStyle。
如何设置TextView风格(粗体或斜体)在Java和不使用XML布局?
换句话说,我需要用Java编写android:textStyle。
当前回答
它会是
yourTextView.setTypeface(null,Typeface.DEFAULT_BOLD);
和斜体应能与替换字体。DEFAULT_BOLD与字体。
让我知道它是如何工作的。
其他回答
你可以这样尝试:
<string name="title"><u><b><i>Your Text</i></b></u></string>
在AndroidX中使用简化标签时,请考虑使用HtmlCompat.fromHtml()
String s = "<b>Bolded text</b>, <i>italic text</i>, even <u>underlined</u>!"
TextView tv = (TextView)findViewById(R.id.THE_TEXTVIEW_ID);
tv.setText(HtmlCompat.fromHtml(s, FROM_HTML_MODE_LEGACY));
TextView text = (TextView)findViewById(R.layout.textName);
text.setTypeface(null,Typeface.BOLD);
尝试通过java代码设置你的TextView样式
txt1.setTypeface(null,Typeface.BOLD_ITALIC);
试试这个:
TextView textview = (TextView)findViewById(R.id.textview_idname);
textview.setTypeface(null,Typeface.BOLD);