Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android alert dialog button background

Tags:

dialog

alert

In Android Alert Dialog : dialog.getButton is not available How to change the background of the Positive button in laert dialog

like image 577
ihsan Khan Avatar asked Jun 23 '26 01:06

ihsan Khan


2 Answers

You need to write it after dialog.show();

AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(NewApplication.this);
    alertDialogBuilder.setCancelable(false).setNegativeButton("Yes",new  DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {

        }
    });
    AlertDialog alertDialog = alertDialogBuilder.create();
    alertDialog.show();
    alertDialog.getButton(Dialog.BUTTON_NEGATIVE).
       setBackgroundColor(Color.parseColor("#3399ff"));

I think this has been addressed here before, IRC.

Check these answers posted earlier on a similar issue:

Android Button modify Question.

Good links and answers there.

like image 25
Robt Avatar answered Jun 25 '26 19:06

Robt