如何在WebView中显示HTML文件?

时间:2013-12-26 19:06:57

标签: android webview

如何打开WebView

private void abriArquivo(String nomeArquivo) {

    File targetFile = new File(nomeArquivo);
    Uri targetUri = Uri.fromFile(targetFile);

    Intent intent;
    intent = new Intent(Intent.ACTION_VIEW);
    intent.setDataAndType(targetUri, "application/html");

    try {
        startActivity(intent);
    } catch (ActivityNotFoundException act) {
        exibeMensagemErro(" ");
    } catch (Exception e) {
        exibeMensagemErro(e.getMessage());
    }

}

1 个答案:

答案 0 :(得分:1)

我认为你可以使用WebView 在xml中插入Web视图,如

<WebView
        android:id="@+id/webView1"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

现在,从您的Activity类

final WebView web = (WebView)findViewById(R.id.webView1);
    web.loadUrl("your_url");