开发者

TextView does not display < symbol

开发者 https://www.devze.com 2023-02-23 08:01 出处:网络
TextView does not display the < symbol. How can I make it so i开发者_如何转开发t does?HTML Encoding

TextView does not display the < symbol.

How can I make it so i开发者_如何转开发t does?


HTML Encoding

Try htmlEncode() from android.text.TextUtils

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

HTMLDecoding

To decode HTML encoded Strings use fromHtml(htmlEncodedString) from android.text.Html

Html.fromHtml(htmlEncodedString).toString();

[EDIT] You asked how you must proceed after retrieving the TextView by its ID from the resource XML. You would set its text like that:

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

Don't forget to import android.text.TextUtils first!


Use the HTML entity &lt;.

0

精彩评论

暂无评论...
验证码 换一张
取 消