在webview中瀏覽頁面的時候,實現在點選退出按鈕的時候,返回上一頁而不是直接退出
阿新 • • 發佈:2019-02-15
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
// TODO Auto-generated method stub
if ((keyCode == KeyEvent.KEYCODE_BACK)&& wv.canGoBack()) {
wv.goBack();
return true;
}
else if (keyCode == KeyEvent.KEYCODE_BACK) {
if (!is2CallBack) {
is2CallBack = true;
ImageView toast_imageview = new ImageView(this);
toast_imageview.setImageResource(R.drawable.quit);
Toast showToast = new Toast(this);
showToast.setView(toast_imageview);
showToast.setDuration(Toast.LENGTH_LONG);
showToast.show();
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
is2CallBack = false;
}
}, 2500);
} else {
android.os.Process.killProcess(android.os.Process.myPid());
}
}
return true;
}
public boolean onKeyDown(int keyCode, KeyEvent event) {
// TODO Auto-generated method stub
if ((keyCode == KeyEvent.KEYCODE_BACK)&& wv.canGoBack()) {
wv.goBack();
return true;
}
else if (keyCode == KeyEvent.KEYCODE_BACK) {
if (!is2CallBack) {
is2CallBack = true;
ImageView toast_imageview = new ImageView(this);
toast_imageview.setImageResource(R.drawable.quit);
Toast showToast = new Toast(this);
showToast.setView(toast_imageview);
showToast.setDuration(Toast.LENGTH_LONG);
showToast.show();
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
is2CallBack = false;
}
}, 2500);
} else {
android.os.Process.killProcess(android.os.Process.myPid());
}
}
return true;
}