Android AlertDialog Move PositiveButton to the rig

2019-02-16 08:40发布

I'm new with android.

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

The default is PositiveButton: Left, NegativeButton: Right

Can you let me know how can I move the PositiveButton to the right side & NegativeButton to the left side?

Is there any chance/trouble if Negativebutton cause a bad sound when pressing OK, if We change text "OK" to NegativeButton & "Cancel" to PositiveButton.

My Code:

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

dialog = builder.create();

Thanks, Angel

7条回答
来,给爷笑一个
2楼-- · 2019-02-16 09:15

This might not be a direct answer. But just some information on related topic. From this thread in Google's own forum, Romain guy said..

Going forward the order of positive/negative buttons will be the one used in ICS.

and the convention per OS version is

  • On devices prior to Honeycomb, the button order (left to right) was POSITIVE - NEUTRAL - NEGATIVE.
  • On newer devices using the Holo theme, the button order (left to right) is now NEGATIVE - NEUTRAL - POSITIVE.

If it is a convention, that android/Google wants to follow, isn't it better you follow the same, since your users won't be using your app alone. After all user friendliness is the first thing a developer looks for..

查看更多
登录 后发表回答