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

后端 未结 7 1965
南方客
南方客 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:43

    I have figured out that there is a space layout between the neutral button and -ve/+ve buttons with the place "1" in the buttonBarLayout in which the buttons.

    So, at first we need to remove that space and or make it's visibility GONE (invisible will let it still takes a space in the buttonBarLayout) also we better to use method onShowListner better that doing that after showing the dialog by:

     alertDialog.setOnShowListener(new DialogInterface.OnShowListener() {
            @Override
            public void onShow(DialogInterface dialog) {
                Button neutralButton = alertDialog.getButton(AlertDialog.BUTTON_NEUTRAL);
                LinearLayout view = (LinearLayout) neutralButtonOrAnyOtherBtnFromThe3Btns.getParent();
                Space space= (Space) view.getChildAt(1);
            }
     });
    

    then the rest is your design, wish that helps

提交回复
热议问题