我有一个字符串.
String text= //Some String That I know
String textToBeColored = //Some Letter User enters at run time
Run Code Online (Sandbox Code Playgroud)
如何在我的String中更改用户在运行时输入的特定字母的颜色.
Nis*_*hia 10
我假设你想要用户选择在字符串中突出显示的特定文本.下面应该可以帮到你.
String text = "abcada";
String textToBeColored = "a";
String htmlText = text.replace(textToBeColored,"<font color='#c5c5c5'>"+textToBeColored +"</font>");
// Only letter a would be displayed in a different color.
txtView.setText(Html.fromHtml(htmlText);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7843 次 |
| 最近记录: |