`

android WebView 回退与退出

 
阅读更多

转于:http://hi.baidu.com/chen88358323/item/44d60c0aa7a3d930a3332af3

 

---------------------------------------------------------------------------------------------------------

 

public boolean onKeyDown(int keyCode, KeyEvent event) {//捕捉返回键

       if ((keyCode == KeyEvent.KEYCODE_BACK) && webview.canGoBack()) {   

       webview.goBack();   

           return true;   

       }else if(keyCode == KeyEvent.KEYCODE_BACK){

           ConfirmExit();//按了返回键,但已经不能返回,则执行退出确认

           return true; 

       }   

       return super.onKeyDown(keyCode, event);   

   }

   public void ConfirmExit(){//退出确认

       AlertDialog.Builder ad=new AlertDialog.Builder(this);

       ad.setTitle("退出");

       ad.setMessage("是否退出软件?");

       ad.setPositiveButton("是", new DialogInterface.OnClickListener() {//退出按钮

           @Override

           public void onClick(DialogInterface dialog, int i) {

               // TODO Auto-generated method stub

               finish();//关闭activity

 

           }

       });

       ad.setNegativeButton("否",new DialogInterface.OnClickListener() {

           @Override

           public void onClick(DialogInterface dialog, int i) {

               //不退出不用执行任何操作

           }

       });

       ad.show();//显示对话框

   }

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics