Webview on Android and local CSS files
Hi,
I would like to ask how can I load a local CSS file in a webview on Android. It works on iPhone just writing for example "/css/style.css". It doesn't work on Android. I've tried with "file:///css/style.css" as well without success.
Thanks
5 Answers
-
I've found the answer to my own question. You need to handle the urls in different ways on iPhone and Android.
On Android you need to use this way: ./ (with single dot)
I think it is a kind of bug. -
How are you passing content into the webview? (Through the url or the html property?)
-
Through the html property. I generate the HTML from the code.
-
Hmm.. we're probably not setting the root URL correctly. Can you try "app://css/style.css" as your URL?
-
Was there ever a solution to this problem? I'm having it as well. I tried 4 methods of linking:
../css/style.css
/css/style.css
app://css/style.css
file:///css/style.css
I ran the iPhone emulator to make sure my paths were correct and it worked just fine in every case. But getting external CSS in android just doesn't seem to work.