如何设置TextView风格(粗体或斜体)在Java和不使用XML布局?

换句话说,我需要用Java编写android:textStyle。


当前回答

你可以这样尝试:

<string name="title"><u><b><i>Your Text</i></b></u></string>

其他回答

试试这个:

TextView textview = (TextView)findViewById(R.id.textview_idname);
textview.setTypeface(null,Typeface.BOLD);

尝试通过java代码设置你的TextView样式

txt1.setTypeface(null,Typeface.BOLD_ITALIC);
TextView text = (TextView)findViewById(R.layout.textName);
text.setTypeface(null,Typeface.BOLD);
//leveraging the extension functions
fun TextView.makeBold(){
    this.setTypeface(this.typeface,Typeface.BOLD)
}


yourTextView.makeBold()

在我的例子中:

1 -设置文本

2 -设置字体

holder.title.setText(item.nome);
holder.title.setTypeface(null, Typeface.BOLD);