【问题标题】:Loading inline CSS in Android Webview problem在 Android Webview 问题中加载内联 CSS
【发布时间】:2020-05-07 17:02:40
【问题描述】:

我正在开发一个基于 android 的 webview 应用程序——HTML、CSS 和 Javascript 是动态构建的——我以前做过这个,但遇到了一个非常疯狂的问题。当 css 开始在 webview 中加载时,它会在 # 颜色处停止加载 - CSS 构建如下:

    String h1 =
            ".sexy_line{\n" +
                    "    display:block;\n" +
                    "    border:none;\n" +
                    "    color:transparent;\n" +
                    "    height:6px;\n" +
                    "    background:black;\n" +
                    "    background: -webkit-gradient(radial, 50% 50%, 0, 50% 50%, 450, from(#2626ff), to(#ffffff00));\n" +
                    "}\n"   +
                    ".floatBottom\n" +
                    "     {\n" +
                    "     position: absolute; \n" +
                    "     bottom: 0;\n" +
                    "     }\n";
return h1;
}

它从字面上停止加载:

background: -webkit-gradient(radial, 50% 50%, 0, 50% 50%, 450, from(

环境:

Android:平板电脑 7.1.1 开发环境:Android Studio 3.5.3

任何帮助将不胜感激---谢谢

更新:我正在使用以下方法加载页面:

 wv = findViewById(R.id.idWebView);            
 settings.setDefaultTextEncodingName("utf-8");
 wv.loadData(webInterface,"text/html","UTF-8");

【问题讨论】:

  • 刚刚意识到,只要 CSS 脚本中有 #,css 就会停止加载。
  • 问题,有没有人注意到 SDK Re 中的 webview 问题; 29. 当我回到 25 岁时,一切似乎都完美无缺。这是一个已知问题吗

标签: android css webview


【解决方案1】:

更新目标 SDK 后遇到同样的问题。 通过 base64 编码我的 HTML 并在编码中传递 base64 解决了这个问题:

// instructions is the HTML string   

 webView.loadData(Base64.encodeToString(instructions.getBytes(), Base64.DEFAULT), "text/html", "base64");

请在此处查看文档中的蓝色框: WebView.loadData

blue box

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-07-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多