gpt4 book ai didi

android - TextView 不显示 < 符号

转载 作者:搜寻专家 更新时间:2023-11-01 09:14:39 26 4
gpt4 key购买 nike

TextView 不显示 <符号。

我怎样才能做到这一点?

最佳答案

HTML 编码

尝试 android.text.TextUtils 中的 htmlEncode()

TextUtils.htmlEncode("My String with <");

HTML解码

要解码 HTML 编码的字符串,请使用来自 android.text.Html 的 fromHtml(htmlEncodedString)

Html.fromHtml(htmlEncodedString).toString();

[编辑]您询问在通过资源 XML 中的 ID 检索 TextView 后必须如何处理。你可以这样设置它的文本:

TextView t=(TextView)findViewById(R.id.textView);
t.setText(TextUtils.htmlEncode("My HTML encoded String with <"));

不要忘记先导入android.text.TextUtils!

关于android - TextView 不显示 < 符号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5622253/

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