Appcompat Alert Dialog Action button background On pressed state

前端 未结 3 1582
既然无缘
既然无缘 2021-02-04 17:41

I am trying new AlertDialog from appcompat v7 22.1.1.

It works pretty well (In all android versions) as in image.

3条回答
  •  不要未来只要你来
    2021-02-04 18:27

    I have the Answer for the 3rd Questions
    ( How can I have different colors of action buttons (Is it possible)? )

    Code:

    // Initialize AlertDialog & AlertDialog Builder
    AlertDialog.Builder builder = new AlertDialog.Builder(YourActivity.this);
    builder.setTitle("AlertDialog Title");
    ...........
    ......... 
    //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));
       }
    

    Happy Coding :)

提交回复
热议问题