final AlertDialog dialog = new AlertDialog.Builder(activity).create();dialog.show(); 1 这里必须先设置
//2 TODO 自定义View View dialogView = inflater.inflate(R.layout.dialog_gps_layout, null, false); View divider = dialogView.findViewById(R.id.divider1);RelativeLayout cancelRL = (RelativeLayout) dialogView .findViewById(R.id.cancel_rl);RelativeLayout comfirmRL = (RelativeLayout) dialogView .findViewById(R.id.confirm_rl);TextView tvTitle = (TextView) dialogView .findViewById(R.id.dialog_title);TextView tvMessage = (TextView) dialogView .findViewById(R.id.warning_words);TextView tvConfirm = (TextView) dialogView.findViewById(R.id.confirm); if (title == null || "".equals(title)) { tvTitle.setVisibility(View.GONE);} else { tvTitle.setText(title);} tvMessage.setText(message);tvMessage.setGravity(Gravity.CENTER);cancelRL.setVisibility(View.GONE); if(set_button_green){ tvConfirm.setTextColor(activity.getResources().getColor(R.color.primary_color));}else{ tvConfirm.setTextColor(activity.getResources().getColor(mConfirmBtnColor));} tvConfirm.setText(confirmBtnText); //3 设置View 的尺寸WindowManager windowManager = activity.getWindowManager();Display display = windowManager.getDefaultDisplay();WindowManager.LayoutParams lp = dialog.getWindow().getAttributes();lp.width = (int)(display.getWidth());lp.height = (int)(display.getHeight());dialog.getWindow().setAttributes(lp); //4 设置View dialog.getWindow().setContentView(dialogView);
这种方案可以解决 全屏的显示。
No comments:
Post a Comment