有没有可能在Android提供TextView的一些文本在Java代码中的setText(文本)函数与基本标签如和 用下划线标出字样?
是的,你可以使用Html.fromhtml()方法:
textView.setText(Html.fromHtml("this is <u>underlined</u> text"));
定义一个string为:
<resources> <string name="your_string">This is an <u>underline</u> text demo for TextView.</string> </resources>
您可以使用SpannableString类中的UnderlineSpan:
SpannableString content = new SpannableString(<your text>); content.setSpan(new UnderlineSpan(), 0, content.length(), 0);
那么就使用textView.setText(content);
你可以在TextView上使用几乎所有的HTML标签。 在这里看到一个例子。
tobeunderlined= <u>some text here which is to be underlined</u> textView.setText(Html.fromHtml("some string"+tobeunderlined+"somestring"));