我有一个字符串。
String text= //Some String That I know
String textToBeColored = //Some Letter User enters at run time
如何更改用户在运行时在我的字符串中输入的特定字母的颜色。
最佳答案
我假设您希望在字符串中突出显示用户选择的特定文本之类的内容。下面应该可以帮助您做到这一点。
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);
关于java - 如何在 java/android 中更改字符串中特定字符的颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25138389/