我想将我的本地html文件显示到webview中。我使用以下代码:

WebView wv;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    wv=new WebView(this);
    setContentView(wv);

    try {
        InputStream stream = this.getAssets().open("index.html");
        int sreamsize = stream.available();
        byte[] bufer = new byte[sreamsize];
        stream.read(bufer);
        stream.close();
        String html= new String(bufer);
        wv.loadData(html, "text/html", "UTF-8");

    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}


现在,我可以看到没有CSS和JS效果的webview元素。如何解决呢?

最佳答案

尝试这个:-

WebView wv;
  wv = (WebView) findViewById(R.id.webView1);
       WebSettings webViewSettings = wv.getSettings();
       webViewSettings.setJavaScriptEnabled(true);
       webViewSettings.setDomStorageEnabled(true);
       wv.loadUrl("file:///android_asset/index.html");

10-02 15:14