Issue
The source HTML string (including the symbol) is coming from the strings.xml resource file, and is destined to be displayed in a WebView. I've tested with this in the resources:
<string name="MY_STRING">®</string>
- Using the actual trademark symbol in the resources (®), the projects builds, but when displayed in the WebView it shows as "®" (i.e. an "A" circumflex, followed by the registered trademark symbol) - i.e. two characters are shown, the first incorrect & unwanted.
- I see the same result when using the entity reference,
®
- Using
®
fails, and the project does not build.
This is the code that pushes the string resource into the WebView:
String html = getString(R.string.MY_STRING);
((WebView)findViewById(R.id.terms_web_view)).loadData(html, "text/html", "UTF-8");
I also tried this, but it did not help: webView.getSettings().setDefaultTextEncodingName("UTF-8");
I pushed the HTML string to Logcat, and it looks fine - it shows the symbol correctly. So if the string is ok, and the WebView is set to use UTF-8, why is the symbol not displaying correctly?
UPDATE I tested on other devices. I can only reproduce this issue on a Galaxy Nexus on Android v4.04. On a Nexus One v2.3.x, Wildfire S on v2.3.x and a Samsung Tab 10.1 on v3.2, it works fine. I've changed the question title to clarify this is an ICS issue.
Solution
String resources are not designed to hold arbitrary HTML, including arbitrary entity references.
You might be able to get an arbitrary entity reference to work if you pre-escape it:
<string name="MY_STRING">&reg;</string>
IIRC, that should decode to ®
after your call to getString()
.
At the end of the day, you need to get ®
to WebView
. If you cannot determine a way to do that with a string resource, you will need to store this value someplace else.
Answered By - CommonsWare
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.