方式一:普通dialog
private void showDialog() {
Dialog dialog = new Dialog(this);
View inflate = LayoutInflater.from(this).inflate(R.layout.layout_dialog, null);
dialog.setContentView(inflate);
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));//必须有
dialog.getWindow().setDimAmount(0.5f);//设置背景透明度,0是完全透明
dialog.getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.MATCH_PARENT);//必须有不然部分android机型不显示布局
dialog.show();
}
方式二:appcompatdialog
Dialog dialog = new AppCompatDialog(getActivity()); dialog.setContentView(R.layout.dialog_view); dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));//设置背景透明 dialog.getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.MATCH_PARENT);//必须有,不然部分android机型不会显示布局 dialog.show();;