为什么在Android中无法更改资源文件中字符串的颜色? [英] Why can't the color of a string from resource file be changed in Android?
本文介绍了为什么在Android中无法更改资源文件中字符串的颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
tvName是TextView控件,世界"的颜色已更改,但保罗"的颜色未更改,为什么?
tvName is TextView control, the color of "World" has changed, but color of "Paul" hasn't changed, why?
还有,在Android Studio 3.1.3中,我得到提示'fromHtml(String!):Spanned!'".已弃用.在Java中已弃用",如何解决?现在,我将Android Studio 3.1.3与Kotlin 1.2.50结合使用
And more, in Android Studio 3.1.3, I get the prompt "'fromHtml(String!): Spanned!' is deprecated. Deprecated in Java" , how can I fix it? Now I use Android Studio 3.1.3 with Kotlin 1.2.50
图片
<string name="aa">
Hello <font color='#0000FF'>Paul </font> !
</string>
val s=mContext.getString(R.string.aa)+" Hello <font color='#0000FF'>World </font>"
tvName.text= Html.fromHtml(s)
推荐答案
尝试一下
<string name="aa">Hello <![CDATA[<font color=#0000FF>Paul!</font>]]></string>
比这样使用
String value=getString(R.string.aa)+" Hello <font color='#0000FF'>World </font>";
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
myTextView.setText(Html.fromHtml(value,Html.FROM_HTML_MODE_LEGACY));
}else {
myTextView.setText(Html.fromHtml(value));
}
输出
这篇关于为什么在Android中无法更改资源文件中字符串的颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文