Android AlertDialog Move PositiveButton to the right and NegativeButton on the left

后端 未结 7 1959
南方客
南方客 2021-01-07 23:11

I\'m new with android.

Currently I want to show an AlertDialog box with \'OK\' & \'Cancel\' buttons.

The default is PositiveButton: Left, Ne

7条回答
  •  既然无缘
    2021-01-07 23:52

    This is not the most elegant of ways but it will do what you want

    AlertDialog.Builder builder = new AlertDialog.Builder(SUtils.getContext());
                builder.setMessage("Confirmation?")
                    .setCancelable(false)
                    .setNegativeButton("OK", new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int id) {
                            //TOdo
                            dialog.cancel();
                        }
                    })
                    .setPositiveButton("Cancel", new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int id) {
                            //TOdo
                        }
                    })
    
    
                diaglog = builder.create();
    

    Just make the Cancel button as positive and the Ok button as negative.

提交回复
热议问题