2012-08-06 67 views
1

用webView显示html页面很容易。如下:如何显示本地文件.html

why = (WebView) findViewById(R.id.webView); 
String htmlStr = "http://myhtml"; 
why.loadUrl(htmlStr); 

但我的困难是在本地显示一个html页面file.html。 我应该把我的file.html放在我的项目中以及WebView的调用如何?

非常感谢您的回复,对不起我的英文不好。

回答

3

把那个.html文件在项目的assets文件夹,并使用下面的代码 -

WebView wv = (WebView)findViewById(R.id.webview1); 
wv.loadUrl("file:///android_asset/index.html"); 
wv.setWebViewClient(new WebViewClient() { 
     @Override 
     public boolean shouldOverrideUrlLoading(WebView view, String url) 
     { 
     view.loadUrl(url); 
     return true; 
     } 
    }); 
+0

非常感谢你的回答,这就是我一直在寻找。 问题已解决。 – Setsuna 2012-08-06 07:37:40

+0

不客气。 – Praveenkumar 2012-08-06 07:38:27

相关问题