如何将字符串的一部分转换为斜体? [英] How to convert part of a string to italics?

查看:72
本文介绍了如何将字符串的一部分转换为斜体?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将 animal.getScientificName 设为斜体(下面的代码).我正在使用列表视图,并在列表视图中设置文本.我不仅希望将文本"视图的一部分包含在斜体中,还是我可以完成此操作吗?我已附上以下代码的一部分,感谢您的帮助.

I want to make animal.getScientificName as Italics(code below). I'm using a List View and setting the text in the listview. I wan't only part of the Text view to be in Italics, Is there anyway I can accomplish this. I have attached part of the code below, Thanks for your help.

String[] listNames;

listNames[ i ] = animal.getName().toUpperCase().replaceAll( "_" , " " ) + " \n\n" + "+animal.getScientificName()+"; 


array_sort = new ArrayList( Arrays.asList( listNames) ); 
tv.setText( array_sort.get( position ) );

推荐答案

使用 Html.fromHtml :

listNames[ i ] = animal.getName().toUpperCase().replaceAll( "_" , " " ) + " \n\n" + "<em>+animal.getScientificName()+</em>"; 


array_sort = new ArrayList( Arrays.asList( listNames) ); 
tv.setText(Html.fromHtml(array_sort.get( position ) ));

有关更多信息,请参见

for more info, refer this

这篇关于如何将字符串的一部分转换为斜体?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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