Val*_*ale 9 android webview android-webview
可能它会有一个简单的解决方案,但我在这里阅读了很多线程,但没办法.在ListView中,如果我点击一行它会打开一个新的活动.在那个活动中,我创建了一个httpget,然后我从httpget(检索到的网页的一部分)创建了一个html字符串.
所以我只是做一个loadDataWithBaseURL("http://base_path.com/", html, mime, encoding, null).
它按预期工作,我查看带有链接和图像的网页.现在问题来了......如果我点击一个图像,我会在那个窗口看到大图像,但是一旦按下手机上的"背面",我就会看到一个白页.我知道它是由"null"参数引起的但是...我应该再次看到html页面了吗?我试图把"html"而不是null但我在webview中看到了html代码!
这是我onKeyDown覆盖后退按钮:
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
// Check if the key event was the BACK key and if there's history
if ((keyCode == KeyEvent.KEYCODE_BACK) && webView.canGoBack()) {
webView.goBack();
return true;
}
// If it wasn't the BACK key or there's no web page history, bubble up to the default
// system behavior (probably exit the activity)
return super.onKeyDown(keyCode, event);
}
Run Code Online (Sandbox Code Playgroud)
小智 7
我在这个答案中找到了一些信息: Android:WebView的方法goBack()显示一个空白页面
您需要提供一个URL,以便在您致电时重新登录
loadDataWithBaseURL("http://base_path.com/", html, mime, encoding, null);
Run Code Online (Sandbox Code Playgroud)
您传递的是null,因此默认为'about:blank'.试试这个:
String baseUrl = "http://base_path.com/";
loadDataWithBaseURL(baseUrl, html, mime, encoding, baseUrl + filename);
Run Code Online (Sandbox Code Playgroud)
作为解决方法,我进行了以下活动。
通过这种方式,图像会加载到默认的 Android 浏览器中,我可以使用后退按钮将其关闭。
离开 WebView 是不好的,但我别无选择。
| 归档时间: |
|
| 查看次数: |
4527 次 |
| 最近记录: |