Android,将 WebView 与 loadData 一起使用

标签 android android-webview

我正在尝试像这样使用 WebView:

    String html = " <html><body> 
    <table style\"background-color: #0a82a4; color: #ffffff;\"> 
       ... stuff ...
    </table>"
    </body>
    </head>";

    html.replace("#", "%23");
    html.replace("\\", "%27");
    html.replace("?", "%3f");
    html.replace("%", "%25");

    myWebview.loadData(html, "text/html", "utf-8");

它可以工作,但是当在样式标签中添加 width=100% 时,webView 无法加载数据。

我使用了这个引用:http://developer.android.com/reference/android/webkit/WebView.html#loadData(java.lang.String, java.lang.String, java.lang.String)

哈哈,解决了:

html = html.replace("%", "%25");
html = html.replace("#", "%23");
html = html.replace("\\", "%27");
html = html.replace("?", "%3f");

最佳答案

您是否看过位于 here 的开发指南中的 HelloWorld 示例?

关于Android,将 WebView 与 loadData 一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7125976/

相关文章:

Android WebView VS 手机浏览器

android - 如何在 webview 中打开第 3 方 URL 上的“选择文件” Intent ?

android - 我如何加载图像 url 以适合我在 android 中的 webview?

android - WebView iframe 忽略 frameborder ="0"

android - 右对齐 LinearLayout 的 imageView

java - 如何在应用程序中创建应用内结算?

javascript - 如何在 webview 中加载完整的谷歌图书网址?

android - 在 Android 上调试时 RxJava 缓存线程中的 InterruptedException

java - 在 android 的父级或祖先上下文中找不到方法 onClickcrea(View) :onClick

Android WebView 硬件呈现奇怪的 Artifact 问题