Change button color in AlertDialog

后端 未结 16 2307

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

16条回答
  •  遥遥无期
    2020-12-02 22:52

    Here is some example :

    AlertDialog.Builder b = new AlertDialog.Builder(all.this);
    
    b.setMessage("r u wan't 2 exit");
    b.setCancelable(false);
    
    b.setNegativeButton("no", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            dialog.cancel();    
        }
    });
    
    b.setPositiveButton("yes", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            Intent i=new Intent(getBaseContext(), s.class);
            startActivity(i);
        }
    });
    
    AlertDialog a=b.create();
    
    a.show();
    
    Button bq = a.getButton(DialogInterface.BUTTON_NEGATIVE);  
    bq.setBackgroundColor(Color.BLUE);
    

提交回复
热议问题