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.

Specur
  • 3,240
  • 4
  • 23
  • 25

1 Answers1

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.

Peter Knego
  • 79,991
  • 11
  • 123
  • 154