android - 带有字体标签的字符串资源不起作用

标签 android html string

我需要帮助显示从下一个字符串资源到 TextView 的颜色

<string name="colored">
  <b>Something working perfectly</b>
  <font color="#F38">Something that doesn't work</font>
</string>

<TextView
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:text="@string/colored"
/>

最佳答案

您必须以编程方式设置它,如下所示:

((TextView)findViewById(R.id.yourTextViewId)).setText(Html.fromHtml(getResources().getString(R.string. colored)));

XML:

<TextView android:id="@+id/yourTextViewId"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
/>

字符串.xml:

<string name="colored"><![CDATA[
  <b>Something working perfectly</b>
  <font color="#F38">Something that doesn't work</font>
]]></string>

关于android - 带有字体标签的字符串资源不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22043716/

相关文章:

php - 数据库中的匹配名称

javascript - jQuery:访问具有特定日期和文本的一串数字的总和

Android 上下文菜单不再出现在模拟器中

javascript - 如何在 webkit 浏览器(如 chrome、safari、opera)中删除 c fakepath?

html - 在另一个 div 的底部调整一个 div

string - Kotlin readln() 无法按预期工作

Android:触发 AJAX 功能不起作用

Android应用程序和Activity之间的静态存储

android - 首次应用安装时间

javascript - 如何使用触摸事件在 Canvas 内移动对象?