I am trying to set the positive, negative and neutral buttons in AlertDialog on drawables, not text.
I have so far been successful using this:
AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setMessage("Are you sure you want to exit?") .setPositiveButton("Save", new DialogInterface.OnClickListener() {...}) .setNeutralButton("Trash", new DialogInterface.OnClickListener() {...}) .setNegativeButton("Cancel", new DialogInterface.OnClickListener() {...}); AlertDialog alert = builder.create(); alert.show(); Button button0 = alert.getButton(AlertDialog.BUTTON_POSITIVE); button0.setCompoundDrawablesWithIntrinsicBounds(this.getResources().getDrawable(R.drawable.ic_menu_save), null, null, null); button0.setText(""); Button button1 = alert.getButton(AlertDialog.BUTTON_NEUTRAL); button1.setCompoundDrawablesWithIntrinsicBounds(this.getResources().getDrawable(R.drawable.ic_menu_delete), null, null, null); button1.setText(""); Button button2 = alert.getButton(AlertDialog.BUTTON_NEGATIVE); button2.setCompoundDrawablesWithIntrinsicBounds(this.getResources().getDrawable(R.drawable.ic_menu_close_clear_cancel), null, null, null); button2.setText("");
This is a workaround because I really just erase the text after the fact. My problem is that you cannot create an instance of a button without setting any text.
Setting "[blank_space]" from the very beginning gives the same result when the image is shifted to the left. Setting zero or "" in the same place completely disables AlertDialog without a button. You can see him pushing left in the picture here:

Can I use only photos? It would be much better than trying to process translations for my simple situation.
source share