gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-03 12:35:07 25 4
gpt4 key购买 nike

我需要帮助显示从下一个字符串资源到 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com