I just added an Alert Dialog that comes up when the back button is clicked. It’s set to the default android alert I believe. Is there anyway to customize how the alert dialog box looks such as change the background or set a drawable to the background? I am new to this so I am not sure what to do. Thanks, and my code is below that I used for the alert dialog.
Alert Dialog:
public boolean onKeyDown(int keyCode, KeyEvent event) {
//Handle the back button
if(keyCode == KeyEvent.KEYCODE_BACK) {
//Ask the user if they want to quit
new AlertDialog.Builder(this)
.setIcon(android.R.drawable.ic_dialog_alert)
.setTitle(R.string.quit)
.setMessage(R.string.really_quit)
.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
//Stop the activity and pause media player
mainSound.pause();
MainActivity.this.finish();
}
})
.setNegativeButton(R.string.no, null)
.show();
return true;
}
else {
return super.onKeyDown(keyCode, event);
}
}
Like this..
Create your xml layout
And then you can set your layout on the builder with the following:
EDIT:
You should rearrange your code to something like this…
Create a AlertDialog.Builder at class level.
In your onCreate() create your AlertDialog