3

I am working on an application with many html pages. I have created these in the raw folder on Eclipse.

I'm going to be making many html files and I want to have only one location for the css file which I want to call in each of the html files. This application works in such a way that the loadData method displays the html page as shown below:

webview.loadData(readTextFromResource(R.raw.gen1), "text/html", "utf-8");

Id appreciate any ideas.

1
  • use assets folder to keep html file & relative reference of css file in that html file Commented Jun 26, 2012 at 9:30

1 Answer 1

7

you can copy html and css files in your project assets and load html file from asset to webview like below code:

    WebView wv;  
    wv = (WebView) findViewById(R.id.webView1);  
    wv.setBackgroundColor(0);
    wv.setBackgroundResource(android.R.color.black);
    wv.setWebChromeClient(new WebChromeClient());
    wv.setWebViewClient(new WebViewClient());
    wv.getSettings().setJavaScriptEnabled(true);
    wv.getSettings().setPluginsEnabled(true);
    wv.loadUrl("file:///android_asset/Index_Animation/test.html");

like below screen shot:

enter image description here

and refer css in html file below:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="./style.css" type="text/css" media="screen"><!--This line refer the css file-->

  </head>
    <body bgcolor="#000000">        

                <div class="col_left">
                    <div class="logo">
                        <div class="circles">
                            <div class="circle"></div>
                            <div class="circle1"></div>
                            <div class="circle2"></div>
                        </div>
                        <center>
                        <img src="./Untitled.png" />
                        </center>
                    </div>

                </div>

</body></html>
Sign up to request clarification or add additional context in comments.

1 Comment

In case my html is dynamic data how to use this.

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.