我正在尝试调整AlertDialog的大小,这是我以前做过的,但记不起我是怎么做的。下面是我使用的代码,但它只是在工作。有人能指出我做错了什么吗?
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(getActivity());
alertDialogBuilder
.setMessage(R.string.checkout_journey_selector_popup_title)
.setPositiveButton(R.string.checkout_journey_selector_popup_paylater_button,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
CheckoutHelper.startReservationJourney(getActivity(),
collectibleItems);
}
})
.setNegativeButton(R.string.checkout_journey_selector_popup_paynow_button,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
CheckoutHelper.startPrepayCollectionJourney(getActivity(),
collectibleItems);
}
}).create().show();
Dialog alert = alertDialogBuilder.create();
WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
lp.copyFrom(alert.getWindow().getAttributes());
lp.height = 100;
lp.width = 50;
alert.getWindow().setAttributes(lp);
提前谢谢
最佳答案
你应该把这个换掉
Dialog alert = alertDialogBuilder.create();
WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
lp.copyFrom(alert.getWindow().getAttributes());
lp.height = 100;
lp.width = 50;
alert.getWindow().setAttributes(lp);
用
WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
lp.copyFrom(alertDialogBuilder.getWindow().getAttributes());
lp.height = 100;
lp.width = 50;
alertDialogBuilder.getWindow().setAttributes(lp);
或者试试这个
alertDialog.getWindow().setLayout(600, 400); after alertDialog.show();
先给我反馈