加载本地HTML中的WebView? [英] Load local html in WebView?

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

问题描述

我要加载本地HTML成的WebView无使用文件:///,因为这不允许Cookie。有没有办法使用像localhost的?

I want to load a local html into a WebView WITHOUT using "file:///" because that does not allow cookies. Is there a way to use something like "localhost" ?

其次,我无法找到一种方法,能够在饼干的getSettings()。因为饼干而使用的file:///是不允许的。

Secondly, I could not find a way to enable cookies in the getSettings(). Because cookies are not allowed while using "file:///".

推荐答案

您只能做这样的事情。这从一个字符串变量的解决方案负载HTML:

You can only do something like that. This solution load HTML from a String variable:

String html = "<html><body>Hello, World!</body></html>";
String mime = "text/html";
String encoding = "utf-8";

WebView myWebView = (WebView)this.findViewById(R.id.myWebView);
myWebView.getSettings().setJavaScriptEnabled(true);
myWebView.loadDataWithBaseURL(null, html, mime, encoding, null);

编辑:尝试设置的<一的第一个参数(baseURL时) href="http://developer.android.com/reference/android/webkit/WebView.html#loadDataWithBaseURL%28java.lang.String,%20java.lang.String,%20java.lang.String,%20java.lang.String,%20java.lang.String%29">loadDataWithBaseURL()满足您的需求。

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

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