手记

Android确认提示框界面自定义及封装

View view = View.inflate(activity, R.layout.dialog, null);
TextView text = (TextView) view.findViewById(R.id.text);
TextView confirm = (TextView) view.findViewById(R.id.confirm);
TextView cancel = (TextView) view.findViewById(R.id.cancel);

    if (!StringUtil.isNullOrEmpty(content)) {
        text.setText(content);
    }

    // 创建Dialog
    final AlertDialog dialog = new AlertDialog.Builder(activity).create();
    dialog.setCancelable(false);// 设置点击dialog以外区域不取消Dialog
    dialog.show();
    dialog.setContentView(view);
    dialog.getWindow().setLayout(DensityUtil.getWidth(activity) / 3 * 2,
            LayoutParams.WRAP_CONTENT);//设置弹出框宽度为屏幕宽度的三分之二

    // 确定
    confirm.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            dialog.dismiss();
            confirmListener.onConfirmClick();
        }
    });
5人推荐
随时随地看视频
慕课网APP