问题描述
我用 setTypeface
来设置一个文本加粗(或斜体或其他字体的属性)
TextView的电视= findViewById(R.id.label);...tv.setTypeface(NULL,Typeface.BOLD);...
我如何只删除粗体属性,不改变可能会迄今已设置其他属性?
解决方案 tv.setTypeface(NULL,Typeface.NORMAL);
这将设置样式恢复正常而不改变颜色或大小。
但你不能混用粗体/斜体/下划线的文字这样。如果指定大胆,所有的文字将是大胆。如果你想混我建议使用HTML样式中的文本的样式,然后使用下列code。
tv.setText(Html.fromHtml(yourStringAsHtml));
I use setTypeface
to set a text bold (or italics, or other of the typeface attributes)
TextView tv = findViewById(R.id.label);
...
tv.setTypeface(null,Typeface.BOLD);
...
How do I remove only the bold attribute, without changing other attributes that might have been set so far?
解决方案tv.setTypeface(null,Typeface.NORMAL);
This would set the style back to normal without changing color or size.
But you can't mix bold/italic/underline text this way. If you specify BOLD, all of the text will be bold. If you want to mix the style of the text I suggest using HTML to style the text, and then use the following code.
tv.setText(Html.fromHtml(yourStringAsHtml));