android - Why can't the color of a string from resource file be changed in Android?
问题描述
tvName is TextView control, the color of "World" has changed, but color of "Paul" hasn't changed, why?
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
Image
<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));
}
输出
推荐阅读
- python - 将数据框列字符串值转换为虚拟变量列
- sql - 为什么 postgresql 认为记录为空,而它显然不是?
- laravel - 在 IIS 10 中使用 laravel websocket 时出错
- javascript - 唯一配对数组元素的最佳方法(其中元素是原始类型和数组)
- xcode - 如何在 CarPlay 上显示歌曲
- timer - 可以同时执行两个 Linux 内核计时器处理程序吗?
- python - 过滤在 Pandas 中读取的 CSV 数据
- python - Scrapy:谁能告诉我为什么这段代码不能让我抓取后续页面?
- python - 将复杂 JSON 转换为 excel 或 CSV
- java - Android 8 之后有多少静态广播接收器无法工作?