我想在用户按下手机时显示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用户按下没有再回到应用
这是很好的解决方案 –
我已经使用第二个数字选项 –
现在你能告诉我如何让警报框变得丰富多彩或有吸引力 –