how to add external css file on html page in Android

前端 未结 1 1883
眼角桃花
眼角桃花 2021-01-07 05:53

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 o

相关标签:
1条回答
  • 2021-01-07 06:42

    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>
    
    0 讨论(0)
提交回复
热议问题