Appcompat Alert Dialog Action button background On pressed state

前端 未结 3 1541
既然无缘
既然无缘 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:19

    AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this); builder.setMessage("Title"); builder.setCancelable(true);

    builder.setPositiveButton("OK",
            new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    dialog.cancel();
    
                }
            });
    
    builder.setNegativeButton("Cancel",
            new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    dialog.cancel();
                }
            });
    
    AlertDialog alertdialog = builder.create();
    alertdialog.show();
    
    Button nbutton = alertdialog.getButton(DialogInterface.BUTTON_NEGATIVE);
    nbutton.setBackground(getResources().getDrawable(R.drawable.btn_press_white_rect));
    
    Button pbutton = alertdialog.getButton(DialogInterface.BUTTON_POSITIVE);
    pbutton.setBackground(getResources().getDrawable(R.drawable.btn_press_white_rect));
    
            **btn_press_white_rect.xml**
    
     
     
     
    
    

提交回复
热议问题