Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

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

— asked March 18th 2010 by Adam Wallner
  • android
  • css
  • local
  • mobile
  • webview
0 Comments

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.

    — answered November 16th 2010 by Adam Wallner
    permalink
    1 Comment
    • thanks! the single dot actually works on both Android and iPhone so that seems to be the best option

      — commented November 15th 2011 by Jake Jake
  • How are you passing content into the webview? (Through the url or the html property?)

    — answered March 20th 2010 by Marshall Culpepper
    permalink
    0 Comments
  • Through the html property. I generate the HTML from the code.

    — answered March 22nd 2010 by Adam Wallner
    permalink
    0 Comments
  • Hmm.. we're probably not setting the root URL correctly. Can you try "app://css/style.css" as your URL?

    — answered March 25th 2010 by Marshall Culpepper
    permalink
    0 Comments
  • 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.

    — answered October 6th 2010 by Will Collins
    permalink
    1 Comment
    • This is 2015 and I still have this issue with 3.4.1 on Android. Any authoritative answer on this? Thank you.

      — commented January 9th 2015 by Gopi Reddy
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.