我只需要从我的字符串中更改一个文件的颜色

I need to change the color of only a file from my string

我有以下字符串:

<string name="welcome.location.services">Please <font color='green'>ALLOW</font> Passenger to access your location in order to track your trips.</string>

如果我这样保留它,它将使用默认的绿色为 ALLOW 着色。但我需要一种不同的颜色。我该如何改变它? 尝试过:

<font color='#ff00ff'>ALLOW</font>

但是这样的话字就没有颜色了。 我想在 strings.xml 中执行此操作,因为每种语言我都有更多文件,并且单词长度和起始索引不同,这使得可跨越的字符串难以使用

PS:我尝试使用 HTML.fromHTML 但还是不行:

((TextView)dialog.findViewById(R.id.header4)).setText(Html.fromHtml(context.getString(R.string.welcome_location_services)));

字符串所在位置:

<string name="welcome.location.services">Please <font color='#ffff00d3'>ALLOW</font> Passenger to access your location in order to track your trips.</string>

来自 Ahmed 的 link,我认为这应该有所帮助,<string name="title"> My <![CDATA[ <font color="#ae23ee">]] Cool <![CDATA[ </font> ]] Title</string>

所以这里只有 'Cool' 会使用那种颜色

使用 CDATA 与不应该被 XML 解析器解析的文本数据一起使用。

使用这个:

<string name="welcome.location.services"><![CDATA[<b><font color=#FF0000>ALLOW!</b>]]></string>

有关 CDATA 的更多信息,请查看此 link

try this, and let me know.

String s = "Hello World, I'm the rest.";
 String[] result = s.split(" ", 2);
 String first = result[0];
 String rest = result[1];

 first = "<font color='#EE0000'>red</font>";
 t.setText(Html.fromHtml(first + rest));