Android 不再提醒对话框

app 在首次进入某个界面的时候,有提示需求弹出对话框。如果点击不再提示,下次进去的时候。对话框将 不再弹出。
通用提示框
**Dialog
 */
public class ApproveDialog extends Dialog implements View.OnClickListener {

    // private Context context;
    private String titleStr;
    private String contentStr;
    private String cancelStr;
    private String goStr;

    public interface ApproveDialogHelper {
        void go();

        void cancel();
    }

    private ApproveDialogHelper mConfirmDialogHelper;

    /**
     * 新建时 , 用这个构造函数
     */
    public ApproveDialog(Context context, String titleStr, String contentStr, String goStr, String tv_cancle_authentication, ApproveDialogHelper helper) {
        super(context, R.style.CustomDialog);
        this.titleStr = titleStr;
        this.contentStr = contentStr;
        this.goStr = goStr;
        this.cancelStr = tv_cancle_authentication;
        this.mConfirmDialogHelper = helper;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.authentication_dialog);
        setCanceledOnTouchOutside(true);
        Window window = getWindow();// 获得窗口
        WindowManager manager = window.getWindowManager();// 获得管理器
        Display display = manager.getDefaultDisplay();
        WindowManager.LayoutParams attributes = window.getAttributes();
        attributes.width = (int) (display.getWidth() * 0.8);
        window.setAttributes(attributes);
        init();
    }

    private void init() {
        TextView tv_title = (TextView) findViewById(R.id.authentication_dialog_title);
        TextView tv_content = (TextView) findViewById(R.id.authentication_dialog_content);
        TextView tv_go = (TextView) findViewById(R.id.tv_authentication);
        TextView tv_cancle_authentication = (TextView) findViewById(R.id.tv_cancle_authentication);

        tv_title.setText(titleStr);
        tv_content.setText(contentStr);
        tv_go.setText(goStr);
        tv_cancle_authentication.setText(cancelStr);

        tv_go.setOnClickListener(this);
        tv_cancle_authentication.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.tv_authentication:
                // 确定
                if (mConfirmDialogHelper != null) {
                    mConfirmDialogHelper.go();
                }
                dismiss();
                break;
            case R.id.tv_cancle_authentication:
                // 取消
                if (mConfirmDialogHelper != null) {
                    mConfirmDialogHelper.cancel();
                }
                dismiss();
                break;
            default:
                break;
        }
    }
}

界面:




    

        

        

        

        


            

            

        


    

  

应用:

ApproveDialog dialog;

  //判断接受到的信息
        if (value.endsWith("1")) {
            //不显示
        } else {
            IsshowDialog(getActivity());
        }

 // 是否显示提示框
    @SuppressLint("ApplySharedPref")
    public void IsshowDialog(final Context context) {
        dialog = new ApproveDialog(context, "重要提示", "为在一定范围内保证大家使用安全,新版供求发布的发帖人必须至少完成手机认证和身份认证。\n但汽修宝典目前只提供信息发布,请求职者仔细辨别招聘信息并保证隐私安全。", "同意", "同意并且不再提示", new ApproveDialog.ApproveDialogHelper() {

            @Override
            public void go() {
                dialog.dismiss();
                //将数据保存到sharedPerferences中:
                SharedPreferences pre = getActivity().getSharedPreferences("check_buy", MODE_PRIVATE);
                SharedPreferences.Editor editor = pre.edit();
                editor.putString("is_buy", "0");
                //提交选择的check,并且保存在pre中
                editor.commit();
            }

            @Override
            public void cancel() {
                dialog.dismiss();
                //将数据保存到sharedPerferences中:
                SharedPreferences pre = getActivity().getSharedPreferences("check_buy", MODE_PRIVATE);
                SharedPreferences.Editor editor = pre.edit();
                editor.putString("is_buy", "1");
                //提交选择的check,并且保存在pre中
                editor.commit();
            }
        });
        dialog.show();
    }

你可能感兴趣的:(Android 不再提醒对话框)