我想在用戶按下手機時顯示alertbox。 所以乾脆我用::AlertBox在後面按下android
public boolean onKeyDown(int keyCode, KeyEvent event) {
if ((keyCode == KeyEvent.KEYCODE_BACK)) {
try {
AlertDialog.Builder alertbox = new AlertDialog.Builder(this);
alertbox.setMessage("This is the alertbox!");
alertbox.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface arg0, int arg1) {
Toast.makeText(getApplicationContext(), "'Yes' button clicked", Toast.LENGTH_SHORT).show();
}
});
// set a negative/no button and create a listener
alertbox.setNegativeButton("No", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface arg0, int arg1) {
Toast.makeText(getApplicationContext(), "'No' button clicked", Toast.LENGTH_SHORT).show();
}
});
alertbox.show();
stopService(new Intent(this, BackServices.class));
finish();
} catch (Exception e) {
// TODO: handle exception
}
}
return super.onKeyDown(keyCode, event);
}
but problem is
:當我按下回alertbox節目,但它從應用程序退出。我想停止從應用程序退出,直到用戶按是button.if用戶按下沒有再回到應用
這是很好的解決方案 –
我已經使用第二個數字選項 –
現在你能告訴我如何讓警報框變得豐富多彩或有吸引力 –