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;
        }
    }
}

界面:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
        android:background="@drawable/approve_dialog_style"
        android:minHeight="100dp"
        android:orientation="vertical"
        android:padding="20dp">

        <TextView
            android:id="@+id/authentication_dialog_title"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="10dp"
            android:gravity="center_horizontal"
            android:text="标题"
            android:textColor="@color/gray_66"
            android:textSize="18sp"
            android:textStyle="bold" />

        <View style="@style/line_horizontal_gray" />

        <TextView
            android:id="@+id/authentication_dialog_content"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            android:gravity="left"
            android:padding="5dp"
            android:singleLine="false"
            android:text="提示内容"
            android:textColor="@color/lightblack"
            android:textSize="16sp" />

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="20dp"
            android:orientation="horizontal">


            <TextView
                android:id="@+id/tv_authentication"
                android:layout_width="match_parent"
                android:layout_height="35dp"
                android:layout_gravity="center"
                android:layout_marginRight="10dp"
                android:layout_weight="1"
                android:background="@drawable/login_style"
                android:gravity="center"
                android:lines="1"
                android:text="提交"
                android:textColor="@color/bgcolor" />

            <TextView
                android:id="@+id/tv_cancle_authentication"
                android:layout_width="match_parent"
                android:layout_height="35dp"
                android:layout_gravity="center"
                android:layout_marginLeft="10dp"
                android:layout_weight="1"
                android:background="@drawable/shape_both_gray_gray"
                android:gravity="center"
                android:lines="1"
                android:text="取消"
                android:textColor="@color/bgcolor" />

        </LinearLayout>


    </LinearLayout>

</RelativeLayout>
  <style name="CustomDialog" parent="@android:style/Theme.Dialog">
        <item name="android:windowIsFloating">true</item>
        <item name="android:windowContentOverlay">@null</item>
        <item name="android:windowAnimationStyle">@android:style/Animation.Dialog</item>
        <item name="android:windowSoftInputMode">stateUnspecified|adjustPan</item>
        <item name="android:windowBackground">@android:color/transparent</item>
        <item name="android:windowNoTitle">true</item>
    </style>

应用:

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();
    }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值