在webView android中加载本地html文件 [英] Loading local html file in webView android

查看:2078
本文介绍了在webView android中加载本地html文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须将现有的html文件加载到位于文件系统中此路径的 WebView 中:

  /data/data/com.example.example/files/file.html 

但是,当 WebView 加载它时,我什么都看不到。
谁可以帮我?



WebView 代码(假设path是我上面写的路径):

  WebView webView =(WebView)findViewById(R.id.webView1); 

文件htmlFile = new File(path);
if(htmlFile.exists())
{
webView.loadUrl(htmlFile.getAbsolutePath());



解决方案

试试这个,在文件中加入:/// ,并做一点改动:

  WebView webView =(WebView)findViewById(R.id.webView1); 
webview.loadUrl(file:///data/data/com.example.example/files/file.html);

然而,您可以将文件放入资产中然后执行此操作:

  WebView webView =(WebView)findViewById( R.id.webView1); 
webview.loadUrl(file:///android_asset/file.html);


I have to load an existing html file into a WebView that is located at this path in the file system:

/data/data/com.example.example/files/file.html

But, when the WebView loads it, I don't see anything. Who can help me?

WebView code (assuming path is the path I've written above):

 WebView webView = (WebView)findViewById(R.id.webView1);

  File htmlFile = new File(path);
    if(htmlFile.exists())
    {
        webView.loadUrl(htmlFile.getAbsolutePath());

    }

解决方案

Try this, adding in a file:/// and doing it a little differently:

WebView webView = (WebView)findViewById(R.id.webView1);
webview.loadUrl("file:///data/data/com.example.example/files/file.html");  

Instead of this, however, you could just put the file into your assets folder in the source code, and then do this:

WebView webView = (WebView)findViewById(R.id.webView1);
webview.loadUrl("file:///android_asset/file.html");

这篇关于在webView android中加载本地html文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆