1

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?

2 Answers 2

2

Try:

webViewer.loadDataWithBaseURL("file:///android_asset/", body, "text/html", "UTF-8", null);
Sign up to request clarification or add additional context in comments.

1 Comment

Using "file:///android_asset/" as the baseUrl is required to access files in the assets folder.
2

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\">";

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.