我想在不使用“file:///”的情况下将本地 html 加载到 WebView 中,因为这不允许使用 cookie。有没有办法使用类似“localhost”的东西?
其次,我找不到在 getSettings() 中启用 cookie 的方法。因为使用“file:///”时不允许使用 cookie。
最佳答案
你只能做这样的事情。此解决方案从字符串变量加载 HTML:
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);
编辑:尝试设置 loadDataWithBaseURL() 的第一个参数(baseURL)满足您的需求
关于android - 在 WebView 中加载本地 html?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4543349/