Reputation: 382
HTML file(test.html) is
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width" />
<link href="bootstrap.css" rel="stylesheet" type="text/css"/>
<link href="bootstrap-responsive.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<h1>Hello World!!!</h1>
<a class="btn btn-primary btn-large">
Learn more
</a>
</body>
</html>
HTML and bootstrap css files are placed in assets folder. If I open the HTML file in IE/Firefox, it is displayed correctly. But Android WebView does not render this properly
Code for WebView is
WebView webView = (WebView) findViewById(R.id.webview);
webView.getSettings().setJavaScriptEnabled(true);
String url = "file:///android_asset/test.html";
webView.loadUrl(url);
IE renders it like this
WebView renders it like this
What is wrong?
Upvotes: 10
Views: 8967
Reputation: 461
WebView webView = (WebView) findViewById(R.id.webview);
webView.getSettings().setJavaScriptEnabled(true);
String htmlData ="<link rel=\"stylesheet\" href=\"https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/css/bootstrap.min.css\">"+yourdata;
webview.loadData(htmlData, "text/html", "UTF-8");
Upvotes: 0
Reputation: 10309
Tested on emulator - Android version 4.2 with Bootstrap v2.3.2
Files in my app's assets folder:
bootstrap-responsive.css
bootstrap.css
test.html
No need to add "android.permission.INTERNET" in Android manifest since css files are available locally within the app's asset folder.
Here's a screenshot of how it is rendered. There is no reason why you could not see it unless there are issues with the CSS files (which is again unlikely since you can see the results on browser).
Upvotes: 1
Reputation: 1049
Add this line
webView.getSettings().setDomStorageEnabled(true);
Upvotes: 3