Android自定义dialog 单利模式

package com.newingscom.fpimlockscreen;

import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.view.View;

/**
 * Created by Administrator on 2019/4/1 0001.
 */

public class MSDialogManager {
    private static MSDialogManager msDialogManager = new MSDialogManager();
    private AlertDialog alertDialog;

    public static MSDialogManager newInstance() {
        return msDialogManager;
    }

    public void showDialog(Context context) {
        if (alertDialog == null) {
            AlertDialog.Builder builder = new AlertDialog.Builder(context, R.style.MyDialog);
            View alView = View.inflate(context, R.layout.dialog_lockscreen_lock_remind, null);
            builder.setView(alView);
            alertDialog = builder.create();
            alertDialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
                @Override
                public void onDismiss(DialogInterface dialogInterface) {
                    alertDialog = null;
                }
            });
        }
        alertDialog.show();
    }


    public void dismissDialog() {
        if (alertDialog != null) {
            alertDialog.dismiss();
            alertDialog = null;

        }

    }


}

  


    
    

你可能感兴趣的:(Android)