【发布时间】:2014-01-23 10:24:29
【问题描述】:
我在 Fragment 中有一个 webview,我希望每当我按下后退按钮时它都由导航历史记录控制。
在我的情况下,当我按下后退按钮时,我会离开 webview,但我希望在按下按钮时,我将返回到存储在导航历史记录中的状态(从离开 webview 之前开始)。
请问有什么解决办法吗?
我尝试使用onKey,但它不能解决我的问题。这是我的代码:
public class FragmentAll extends Fragment implements
DialogInterface.OnCancelListener, DialogInterface.OnDismissListener,
OnDownloaExpodTerminated {
public static Fragment newInstance(Context context) {
FragmentAll f = new FragmentAll();
return f;
}
private WebView myWebView;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
(((MainActivity) getActivity()) ).setActionBarTitle("Store");
myWebView = (WebView) v.findViewById(R.id.webView1);
setWebview();
v.setOnKeyListener(new OnKeyListener() {
@Override
public boolean onKey(View arg0, int arg1, KeyEvent arg2) {
// TODO Auto-generated method stub
if (arg1 == KeyEvent.KEYCODE_BACK && myWebView.canGoBack()) {
myWebView.goBack();
return true;
}
return false;
}
});
return v;
}
...
}
【问题讨论】:
标签: android webview fragment state