2

I have a WebView on my Android application which loads (WebView.loadUrl()) different local HTML files from phone's internal storage. I would like to include some custom css styles for them.

Now, I could have my app edit every HTML file and add linking reference for the CSS file.

I could also read the file contents, add the CSS linking and use WebView.loadData() to load it.

But is it possible to do this a lot simpler and efficiently?

Note: The HTML files are downloaded from a website. So editing them manually is not possible in this case, but once downloaded they can be edited via the app if necessary.

1 Answer 1

3

One possibility (I have not tried this):

WebView.loadDataWithBaseURL(String baseUrl, String data, ..)

takes a baseURL for the document to use to resolve relative URLs. Take a look at the CSS url and construct baseURL so that CSS url will reference local CSS file.

Sign up to request clarification or add additional context in comments.

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.