adjfac
adjfac

Reputation: 635

How to reference local css files in a static webview window in android dev?

I've created a static html page to be displayed in the WebView, I've a css file inside the /assets/common.css folder. The code looks like;

String linkCss = "<link rel=\"stylesheet\" href=\"/assets/common.css\" type=\"text/css\">";
String body = "<html><header>" + linkCss + "</header>" + content + "</body></html>";

webViewer.loadDataWithBaseURL("x-data://base", body , "text/html", "UTF-8", null);

Everything display correctly except the CSS isn't being applied. Whats the problem?

Upvotes: 1

Views: 5136

Answers (2)

Mudassir
Mudassir

Reputation: 13174

I think, you should also replace the /assets/common.css with file:///android_asset/common.css in the css link. Try this

String linkCss = "<link rel=\"stylesheet\" href=\"file:///android_asset/common.css\" type=\"text/css\">";

Upvotes: 2

Femi
Femi

Reputation: 64700

Try:

webViewer.loadDataWithBaseURL("file:///android_asset/", body, "text/html", "UTF-8", null);

Upvotes: 2

Related Questions