Dialog弹框(普通的从中间弹出及从底部动画弹出)

private CustomDialog mDialogEdit;
    private TextView mTvTitle;
    private TextView mTvCancel;
    private TextView mTvOK;
    private void showEditDialog(AcademiaPersonBean personBean) {
        if (mDialogEdit == null) {
            mDialogEdit = new CustomDialog(mContext, R.style.style_dialog_add_pic);
            View contentView = View.inflate(mContext, R.layout.dialog_edit_reason, null);
            mDialogEdit.setContentView(contentView);
            mTvCancel=contentView.findViewById(R.id.tv_cancel_edit_dialog);
            mTvOK=contentView.findViewById(R.id.tv_ok_edit_dialog);
            mTvTitle=contentView.findViewById(R.id.tv_title_edit_dialog);

            Window window = mDialogEdit.getWindow();
//        window.setGravity(Gravity.BOTTOM);
//        WindowManager.LayoutParams layoutParams=new WindowManager.LayoutParams();//这样会冲掉style里面的属性
            WindowManager.LayoutParams layoutParams = window.getAttributes();
            layoutParams.width = WindowManager.LayoutParams.WRAP_CONTENT;
            layoutParams.height = WindowManager.LayoutParams.WRAP_CONTENT;
//            layoutParams.dimAmount = 0.3f;
            layoutParams.gravity = Gravity.CENTER;//BOTTOM
            window.setAttributes(layoutParams);
//            window.setWindowAnimations(R.style.dialog_anim);//开启底部动画
            mDialogEdit.setCanceledOnTouchOutside(true);
        }
        mTvCancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mDialogEdit.dismiss();
            }
        });
        mTvOK.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mDialogEdit.dismiss();
            }
        });
        String titleText=String.format(getMyString(R.string.text_forbid_talk_5_somebody),"\""+personBean.personName+"\"");
        mTvTitle.setText(titleText);
        mDialogEdit.show();
    }

 

你可能感兴趣的:(Android基础)