views:

32

answers:

1

Is it possible to add drawables to the positive, negative and neutral buttons of an AlertDialog? If yes, then how?

+1  A: 

After you have built the AlertDialog in onCreateDialog you can use the following code in onPrepareDialog to add an image to the positive button:

@Override
protected void onPrepareDialog(int id, Dialog dialog) {
    super.onPrepareDialog(id, dialog);
    AlertDialog alertDialog = (AlertDialog)dialog;
    Button button = alertDialog.getButton(AlertDialog.BUTTON_POSITIVE);
    button.setCompoundDrawablesWithIntrinsicBounds(this.getResources().getDrawable(
            R.drawable.icon), null, null, null);

}

Trying to add the drawable to the button in the onCreateDialog method does not seem to work.

Frank
Will try and get back to this Frank.
Ragunath Jawahar