Android 如何给新绳子上色?
怎么可能给新文本“e”上色Android 如何给新绳子上色?,android,eclipse,string,Android,Eclipse,String,怎么可能给新文本“e”上色 是的,如果您使用html格式化字符串 您需要使用Html.fromHtml()在XML字符串中使用Html。在布局XML中简单地引用带有HTML的字符串将不起作用 例如: String text = "<font color=#cc0029>Exempl</font> <font color=#ffcc00>e</font>"; myTextView.setText(Html.fromHtml(text); S
是的,如果您使用html格式化字符串 您需要使用Html.fromHtml()在XML字符串中使用Html。在布局XML中简单地引用带有HTML的字符串将不起作用 例如:
String text = "<font color=#cc0029>Exempl</font> <font color=#ffcc00>e</font>";
myTextView.setText(Html.fromHtml(text);
String text=“example”;
myTextView.setText(Html.fromHtml(text);
您需要使用ForegroundColorSpan
final String text = "something something text";
final int n = 4;
final String newText = text.substring(0, n) + "e" + text.substring(n + 1);
final ForegroundColorSpan fcs = new ForegroundColorSpan(Color.RED);
final SpannableString ss = new SpannableString(newText);
ss.setSpan(fcs, n, n + 1, 0);
tv.setText(ss);
我建议使用HTML
标记.Thx,但使用此代码,在“e”变红之前的字母…?!我做错了什么?
final String text = "something something text";
final int n = 4;
final String newText = text.substring(0, n) + "e" + text.substring(n + 1);
final ForegroundColorSpan fcs = new ForegroundColorSpan(Color.RED);
final SpannableString ss = new SpannableString(newText);
ss.setSpan(fcs, n, n + 1, 0);
tv.setText(ss);