我试图在我的 Assets 文件夹中显示一个html文件,但是在Web View 中,我看到的是空白页。我仅从stackflow获得了类似的示例。

 public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    final String mimeType="text/html";
    final String encoding="UTF-8";
    String htmlString="<html><body>";
    Document doc;
    WebView wv= new WebView(this);
    Elements link = null;


    setContentView(wv);
    try{
        InputStream in=getAssets().open("myweb.html");
        byte[] buffer= new byte[in.available()];
        in.read(buffer);
        in.close();
        wv.loadData(new String(buffer), mimeType, encoding);
    }
    catch(IOException e)
    {
        Log.d("MyWebView", e.toString());
    }
}

最佳答案

您可以使用以下方式加载网络 View 的内容

// add a webview with id @+id/the_webwiev to your main.xml layout file
WebView wv = (WebView)findViewById(R.id.the_webview);
wv.loadUrl("file:///android_asset/myweb.html");

关于android - 在Android中显示静态HTML页面,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/5856176/

10-12 01:46
查看更多