9 Jan 2015

Dynamic html and javascript from assets in a WebView | Add external css file on html page in Android

I am trying to display HTML content in a web view. The UI is simple jQuery Mobile. The HTML displays, but the CSS and JavaScript from the assets folder.
Css and js file will resides in assets folder.

Note : Put you .css and .js file in assets folder as well

here is the implementation code

OUTPUT :



WebView  wvSpecification= (WebView)rootview.findViewById(R.id.wvSpecification);

       StringBuilder sb = new StringBuilder();
                     sb.append("<HTML xmlns='http://www.w3.org/1999/xhtml'>" +           
                                  "<HEAD>"+
                                  "<meta name='viewport' content='width=device-width, initial-scale=1'>"+
                                  "<link rel='stylesheet' href=cssfilename.css'/>"+
                                  "<link rel='stylesheet' href= cssfilename.css'/>"+
                                  "<script src= jsfilename.js' type='text/javascript'></script>"+
                                  "</HEAD>"); 

                     sb.append("<body>"+
                                  "<h1>Mobile</h1>"+
                                  "<table class='responsive'>"+
                                  "<tr>"+
                                  "<th>Company Name</th>"+
                                  "<th>Model Name</th>"+
                                  "<th>Version</th>"+
                                  "</tr>"+
                                  "<tr>"+
                                  "<td>Google</td>"+
                                  "<td>Nexus 5</td>"+
                                  "<td>4.4</td>"+
                                  "</tr>"+
                                  "<tr>"+
                                  "<td>HTC</td>"+
                                  "<td>Desire X</td>"+
                                  "<td>4.1</td>"+
                                  "</tr>"+
                                   "<tr>"+
                                  "<td>Samsung</td>"+
                                  "<td>Galaxy s4</td>"+
                                  "<td>4.3</td>"+
                                  "</tr>"+
                                  "</table>"+
                                  "</body>");
                                  sb.append("</HTML>");


                                  wvSpecification.loadDataWithBaseURL("file:///android_asset/",sb.toString(),"text/html","UTF-8",null);


You may like Web View with Progress Dialog visit

I will be happy if you will provide your feedback or follow this blog. Any suggestion and help will be appreciated.
Thank you :)

17 comments:


  1. This is an awesome post.Really very informative and creative contents. These concept is a good way to enhance the knowledge.I like it and help me to development very well.Thank you for this brief explanation and very nice information.Well, got a good knowledge.

    angularjs Training in bangalore

    angularjs Training in electronic-city

    angularjs Training in online

    angularjs Training in marathahalli

    ReplyDelete
  2. I'm here representing the visitors and readers of your own website say many thanks for many remarkable
    python training Course in chennai | python training in Bangalore | Python training institute in kalyan nagar

    ReplyDelete
  3. It is better to engaged ourselves in activities we like. I liked the post. Thanks for sharing.

    Java training in Annanagar | Java training in Chennai

    Java training in Chennai | Java training in Electronic city

    ReplyDelete
  4. This comment has been removed by the author.

    ReplyDelete
  5. Thanks for any other wonderful post. Where else may just anyone get that type of info in such a perfect means of writing? I’ve a presentation next week, and I am on the look for such information.


    angular js training in chennai

    angular js training in velachery

    full stack training in chennai

    full stack training in velachery

    php training in chennai

    php training in velachery

    photoshop training in chennai

    photoshop training in velachery


    ReplyDelete
  6. Amazing article. Your blog helped me to improve myself in many ways thanks for sharing this kind of wonderful informative blogs in live. I have bookmarked more article from this website. Such a nice blog you are providing ! Kindly Visit Us
    angular js training in chennai

    angular js training in tambaram

    full stack training in chennai

    full stack training in tambaram

    php training in chennai

    php training in tambaram

    photoshop training in chennai

    photoshop training in tambaram

    ReplyDelete
  7. I simply unearthed your site and needed to say that I have truly appreciated perusing your blog entries. I want to say thanks for great sharing.
    IELTS Coaching in chennai

    German Classes in Chennai

    GRE Coaching Classes in Chennai

    TOEFL Coaching in Chennai

    Spoken english classes in chennai | Communication training

    ReplyDelete