Android - Make AlertDIalog Buttons A Uniform Size
I have an alert dialog with a positive and negative button added programatically. In the dialog layout there are also two buttons, above the AlertDialog's native buttons. When th
Solution 1:
Figured out a solution... don't know why I didn't think of it before.
I do the following:
mRateConcertDialog.setOnShowListener(new OnShowListener() {
@Override
public void onShow(DialogInterface d) {
Button posButton = mRateConcertDialog.getButton(DialogInterface.BUTTON_POSITIVE);
Button negButton = mRateConcertDialog.getButton(DialogInterface.BUTTON_NEGATIVE);
LayoutParams posParams = (LayoutParams) posButton.getLayoutParams();
posParams.weight = 1;
posParams.width = LayoutParams.MATCH_PARENT;
LayoutParams negParams = (LayoutParams) negButton.getLayoutParams();
negParams.weight = 1;
negParams.width = LayoutParams.MATCH_PARENT;
posButton.setLayoutParams(posParams);
negButton.setLayoutParams(negParams);
}
});
Basically, you have to manipulate the size of the buttons AFTER the dialog is shown. So create an onShowListener and you can just set weights and widths that way. Thanks for the comments, I hope this can help someone in the future.
Post a Comment for "Android - Make AlertDIalog Buttons A Uniform Size"