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);
}
}
使用:
样式:
网友评论