requestFeature() must be called before adding content
com.android.internal.policy.impl.PhoneWindow.requestFeature(PhoneWindow.java:345)
2 com.android.internal.app.AlertController.installContent(AlertController.java:238)
3 android.app.AlertDialog.onCreate(AlertDialog.java:372)
4 android.app.Dialog.dispatchOnCreate(Dialog.java:417)
5 android.app.Dialog.show(Dialog.java:305)
原因:
在Dialog 尚未挂载在窗体时,我们对窗体做了一些参数设定
//这段代码在Dialog onCreate 之前调用就会触发这个异常
WindowManager.LayoutParams params = dialog.getWindow().getAttributes();
params.width = QMUIDisplayHelper.getScreenWidth(context);
params.height = QMUIDisplayHelper.getScreenHeight(context);
dialog.getWindow().setAttributes(params);
dialog.getWindow().setBackgroundDrawableResource(android.R.color.transparent);
dialog.show();
dialog.getWindow().setLayout(QMUIDisplayHelper.dp2px(context, 290),
LinearLayout.LayoutParams.WRAP_CONTENT);
网友评论