在app中總是不小心點擊了退出怎么辦?當然是加個彈出的提示框了,本人新手,就加在主界面上了
@Override public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK) { AlertDialog.Builder bdr=new AlertDialog.Builder(this); bdr.setMessage("確定要退出XX助手嗎?"); bdr.setIcon(R.drawable.ic_book_white_24dp); bdr.setNegativeButton("退出",this); bdr.setPositiveButton("取消",this); bdr.show(); return true; } return super.onKeyDown(keyCode, event); }
@Override public void onClick(DialogInterface dialog, int which) { //處理退出對話框的事項. if (which==DialogInterface.BUTTON_POSITIVE){ } if (which==DialogInterface.BUTTON_NEGATIVE){ finish(); } }
然后運行在模擬器上后一點擊退出鍵,就app無響應掛掉了,很是無語,不知什么原因,但是在真機上能正常運行.