0
WebViewを表示する前にCSSを挿入する方法について助けが必要です。助けをお待ちしています。show WebViewの前にCSSを挿入するには?
WebViewが表示される前に、資産からWebViewにCSSを挿入する必要があります。
WebViewを表示する前にCSSを挿入する方法について助けが必要です。助けをお待ちしています。show WebViewの前にCSSを挿入するには?
WebViewが表示される前に、資産からWebViewにCSSを挿入する必要があります。
あなたのHTML構造にURLコンテンツを手動で読み込む必要があります。このコードをpage.htmlとしてassetsフォルダに配置します。
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=0">
<style type="text/css">
// your css code here
</style>
</head>
<body>
${body}
</body>
</html>
は、Javaコードで:
String pageBody; // get page body by httpUrlConnection or okhttp or...
String html = FileUtils.readFromAssets("page.html", context);
// replace pageBody with ${body} in your html file
html = html.replace("${body}", pageBody);
WebView webView = (WebView) getView().findViewById(R.id.webView);
webView.getSettings().setAllowFileAccess(true);
WebSettings settings = webView.getSettings();
settings.setDefaultTextEncodingName("utf-8");
settings.setJavaScriptEnabled(true);
webView.loadDataWithBaseURL("file:///android_asset/", html, "text/html", "utf-8", null);
たぶん「私はいくつかの助けをしたい」と言うあなたがしようとしたものを表示していません。閉鎖のためのフラグ付けは、これが努力を示さないためです。 – basic