美文网首页
自定义dialog

自定义dialog

作者: 木叶纷飞 | 来源:发表于2018-08-08 15:48 被阅读0次

    public class ConfirmOperationDialogextends AlertDialog {

                public ConfirmOperationDialog(Context context) {

                            super(context, R.style.ConfirmOperationDialog);

                            mContentView = LayoutInflater.from(context).inflate(R.layout.dialog_round_rect, null);

                            ButterKnife.bind(this, mContentView);

                            initParams();

                }

                private void initParams() {

                        WindowManager.LayoutParams p = getWindow().getAttributes();  //获取对话框当前的参数值

                        p.width = LinearLayout.LayoutParams.MATCH_PARENT;

                        p.height = LinearLayout.LayoutParams.WRAP_CONTENT;

                        getWindow().setAttributes(p);

                        getWindow().clearFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);

               }

                public ConfirmOperationDialogsetTitle(String title) {

                        mTvDialogTitle.setVisibility(View.VISIBLE);

                        mTvDialogTitle.setText(title);

                        return this;

                }

                public ConfirmOperationDialogsetMessage(String message) {

                        mTvDialogMessage.setVisibility(View.VISIBLE);

                        mTvDialogMessage.setText(message);

                        return this;

                }

                @OnClick({R.id.tv_dialog_left, R.id.tv_dialog_right})

                public void onViewClicked(View view) {

                            switch (view.getId()) {

                                    case R.id.tv_dialog_left:

                                            if (mListener != null) {

                                            mListener.clickLeft();

                                    }

                                    break;

                                    case R.id.tv_dialog_right:

                                            if (mListener != null) {

                                            mListener.clickRight();

                                    }

                                    break;

                                    }

                                dismiss();

                        }

                        public ConfirmOperationDialogsetLeftButton(String text) {

                                    mTvDialogLeft.setText(text);

                                    return this;

                            }

                    public ConfirmOperationDialogsetRightButton(String text) {

                                mTvDialogRight.setVisibility(View.VISIBLE);

                                mTvDialogRight.setText(text);

                                return this;

                        }

                public interface onClickListener {

                            void clickLeft();

                            void clickRight();

                    }

                public void setDialogListener(onClickListener onClickListener) {

                    this.mListener = onClickListener;

                    }

                @Override

                public void show() {

                        super.show();

                        setContentView(mContentView);

                }

    }

    使用:

    样式:

    相关文章

      网友评论

          本文标题:自定义dialog

          本文链接:https://www.haomeiwen.com/subject/lolsvftx.html