从TextView中而不改变其他属性删除粗体 [英] Remove Bold from textview without changing other attributes

查看:97
本文介绍了从TextView中而不改变其他属性删除粗体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用 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));

这篇关于从TextView中而不改变其他属性删除粗体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆