一开始AlertDialog弹框按钮是这样的:(忽略我随便复制粘贴的弹框内容以及还未美化的界面哈)
然后,想把按钮居中显示:
方法如下:
public void setDialogStyle(){
Button btnPositive = dialog.getButton(AlertDialog.BUTTON_POSITIVE);
Button btnNegative = dialog.getButton(AlertDialog.BUTTON_NEGATIVE);
LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) btnPositive.getLayoutParams();
layoutParams.weight = 10;
btnPositive.setLayoutParams(layoutParams);
btnNegative.setLayoutParams(layoutParams);
}
在这发现的:https://stackoverflow.com/questions/30743038/align-alertdialog-buttons-to-center