自定义AlertDialog的Style并延迟消失Dialog

private AlertDialog dialog;
private static int DIALOG_SUCCESS = 1;
private Handler mHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
// TODO Auto-generated method stub
super.handleMessage(msg);
if (null != dialog) {
if (DIALOG_SUCCESS == msg.what && dialog.isShowing()) {
dialog.dismiss();
finish();
} else
dialog.dismiss();
}
}
};

由于本项目业务需要,布局仅显示附带一张图片的textview。

dialog = new AlertDialog.Builder(this, R.style.NoticeDialogStyle).create();
dialog.show();
dialog.setCanceledOnTouchOutside(false);
Window window = dialog.getWindow();
if (code.equals(Constants.RESULT_OK)) {
window.setContentView(R.layout.include_release_notice_success);
mHandler.sendEmptyMessageDelayed(DIALOG_SUCCESS, 2000);
setResult(REQUEST_RELEASE);
} else {
window.setContentView(R.layout.include_release_notice_fail);
int DIALOG_FAIL = 0;
mHandler.sendEmptyMessageDelayed(DIALOG_FAIL, 2000);
}

其中R.style.NoticeDialogStyle需要在styles文件中自定义:

你可能感兴趣的:(自定义AlertDialog的Style并延迟消失Dialog)