2012-06-26 131 views
2

我正在处理一个有很多html页面的应用程序。我已经在Eclipse上的原始文件夹中创建了这些文件。如何在Android中的html页面添加外部CSS文件

我打算制作很多html文件,并且我只想为每个html文件中要调用的css文件创建一个位置。此应用程序以这样的方式使 loadData方法显示HTML网页的工作,如下图所示:

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

编号欣赏任何想法。

+0

使用资产文件夹保存html文件&rela该HTML文件的css文件tive引用 –

回答

5

你可以从资产复制HTML和CSS文件在你的项目资产和加载HTML文件的WebView像下面的代码:

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"); 

像下面的屏幕截图:

enter image description here

,并参考下面的html文件中的css:

<!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> 
+2

谢谢Dinesh,你的先生是一个救星:)非常感谢! – user788511

+1

万一我的html是动态数据如何使用这个。 – NagarjunaReddy

相关问题