Change button color in AlertDialog

后端 未结 16 2354

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

16条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-02 23:11

    To Change the Buttons color of the AlertDailog

    Code:

    // Initialize AlertDialog & AlertDialog Builder
    AlertDialog.Builder builder = new AlertDialog.Builder(YourActivity.this);
    builder.setTitle(R.String.AlertDialogTitle);
    ...........
    ......... 
    //Build your AlertDialog 
    AlertDialog Demo_alertDialog= builder.create();
    Demo_alertDialog.show();
    
    //For Positive Button:
    Button b_pos; 
    b_pos=Demo_alertDialog.getButton(DialogInterface.BUTTON_POSITIVE);
    if(b_pos!=null){
       b_pos.setTextColor(getResources().getColor(R.color.YourColor));
       }    
    
    
    //For Neutral Button:
    Button b_neu;
    b_neu=Demo_alertDialog.getButton(DialogInterface.BUTTON_NEUTRAL);
    if(b_neu!=null){
       b_neu.setTextColor(getResources().getColor(R.color.YourColor));
       }
    
    //For Negative Button:
    Button b_neg;
    b_neg=Demo_alertDialog.getButton(DialogInterface.BUTTON_NEGATIVE);
    if(b_neg!=null){
       b_neg.setTextColor(getResources().getColor(R.color.YourColor));
       }
    

提交回复
热议问题