Change button color in AlertDialog

后端 未结 16 2367

How can I change the color of the button(s) in an AlertDialog in Android?

16条回答
  •  广开言路
    2020-12-02 23:13

    I wanted to solve this with themes rather than extra code since it feels cleaner to me to have all the styling-related stuff in the styles.xml. What I did was based on Arade's answer and this other question:

    
    

    This will change the color of the button text of any alert dialog you create with style AlertDialogDanger. To do so:

        new AlertDialog.Builder(new ContextThemeWrapper(this, R.style.AlertDialogDanger))
                .setMessage("Really delete?")
                .setPositiveButton("Delete", null)
                .setNegativeButton("Cancel", null)
                .create().show();
    

提交回复
热议问题