在Android的V4.0的WebView显示®注册商标符号? [英] Display ® registered trademark symbol in Android v4.0 WebView?

查看:339
本文介绍了在Android的V4.0的WebView显示®注册商标符号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

源HTML字符串(包括符号)从的strings.xml资源文件来,并注定要被显示在web视图。我已经在资源与这一测试:

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>


  • 使用的资源的实际商标符号(®),项目建立,但在WebView中显示时,显示为®(即一个A抑扬,其次是注册商标符号) - 即2字符被示出,在第一不正确&放大器;没人要。

  • 我看到了同样的结果使用实体引用时,&放大器;#174;

  • 使用&放大器;章; 失败,并且该项目不建

    • 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, &#174;
    • Using &reg; fails, and the project does not build.
    • 这是code是推动字符串资源到的WebView:

      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");
      

      我也试过,但它并没有帮助:
          webView.getSettings()setDefaultTextEncodingName(UTF-8);

      I also tried this, but it did not help: webView.getSettings().setDefaultTextEncodingName("UTF-8");

      我推HTML字符串logcat的,它看起来很好 - 它正确地显示符号。因此,如果字符串是确定的,而web视图设置为使用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?

      更新
      我在其他设备上进行测试。我只能重现此问题上的Galaxy Nexus在Android v4.04。在Nexus One的v2.3.x,野火S在v2.3.x和V3.2三星Tab键10.1,它工作正常。我已经改变了问题的标题,以澄清这是一个ICS问题。

      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.

      推荐答案

      字符串资源没有设计容纳任意的HTML,包括任意实体引用。

      String resources are not designed to hold arbitrary HTML, including arbitrary entity references.

      您的可能的能够得到一个任意实体引用工作,如果你pre-转义:

      You might be able to get an arbitrary entity reference to work if you pre-escape it:

      <string name="MY_STRING">&amp;reg;</string>
      

      IIRC,应该去code到&安培;你的电话后的getString();章

      在这一天结束时,你需要获得&放大器;章; 的WebView 。如果你不能确定的方式来做到这一点与字符串资源,则需要到别的存储该值的某个地方。

      At the end of the day, you need to get &reg; to WebView. If you cannot determine a way to do that with a string resource, you will need to store this value someplace else.

      这篇关于在Android的V4.0的WebView显示®注册商标符号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆