Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/228.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何给新绳子上色?_Android_Eclipse_String - Fatal编程技术网

Android 如何给新绳子上色?

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

怎么可能给新文本“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);
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);