返回按钮关闭 WebView 应用程序
我有一个如下的应用程序,它作为 FullScreen.NoTitleBar 运行:
public class BrowserActivity extends Activity {
private String lastUrl = "http://www.google.com";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
WebView web = (WebView) findViewById(R.id.webview);
WebSettings settings = web.getSettings();
settings.setJavaScriptEnabled(true);
settings.setJavaScriptCanOpenWindowsAutomatically(false);
settings.setSupportMultipleWindows(false);
settings.setSupportZoom(false);
settings.setPluginsEnabled(true);
web.setWebViewClient(new WebViewClient() {
public boolean shouldOverrideUrlLoading(WebView view, String url) {
lastUrl = url;
view.loadUrl(url);
return true;
}
});
web.setVerticalScrollBarEnabled(false);
web.setHorizontalScrollBarEnabled(false);
web.loadUrl(lastUrl);
}
}
“lastUrl”用于处理方向更改,并让用户在导航时位于同一页面上。
但我的问题是,如果用户点击某些链接然后点击返回按钮,应用程序就会关闭,而不是返回页面。我该如何处理?
I have a application as below that runs as FullScreen.NoTitleBar:
public class BrowserActivity extends Activity {
private String lastUrl = "http://www.google.com";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
WebView web = (WebView) findViewById(R.id.webview);
WebSettings settings = web.getSettings();
settings.setJavaScriptEnabled(true);
settings.setJavaScriptCanOpenWindowsAutomatically(false);
settings.setSupportMultipleWindows(false);
settings.setSupportZoom(false);
settings.setPluginsEnabled(true);
web.setWebViewClient(new WebViewClient() {
public boolean shouldOverrideUrlLoading(WebView view, String url) {
lastUrl = url;
view.loadUrl(url);
return true;
}
});
web.setVerticalScrollBarEnabled(false);
web.setHorizontalScrollBarEnabled(false);
web.loadUrl(lastUrl);
}
}
The "lastUrl" is used for handle orientation changes and let the user on the same page that he was while navigating.
But my problem is, if the user follow some links then hit the return button, the application just closes instead of returning a page back. How can I handle it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我通过处理返回并跟踪用户访问的 URL 解决了这个问题。
I solved it by handling returns and keeping track of the URLs visited by the user.