安卓缓冲dialog对话框,创建+使用+封装

package com.hstech.handysystem.prompt;

import android.app.Dialog;
import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.widget.TextView;

import com.hstech.handysystem.R;

    public class LoadingDialog {
    private Dialog loadingDialog;
    private TextView textView;
    private boolean isShowing = false;
    private int count = 0;
    public LoadingDialog(Context context) {
        loadingDialog = new Dialog(context, R.style.MyTheme_AppCompat_Light_Dialog);

        loadingDialog.setContentView(R.layout.loading);
        loadingDialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
        loadingDialog.setCancelable(false);
        textView = (TextView) loadingDialog.findViewById(R.id.loading_message);
    }

    /**
     * 设置消息显示
     *
     * @param message
     */
    public void setMessage(String message) {
        textView.setText(message);
    }

    /**
     * 关闭对话框
     */
    public void dismiss() {
        if(count>0)count--;
        if(count==0) {
            loadingDialog.dismiss();
            isShowing = false;
        }
    }

    public void forceDismiss() {

            loadingDialog.dismiss();
            isShowing = false;

    }

    /**
     * 显示对话框
     */
    public void dialogShow() {
        count++;
        if(!isShowing) {
            loadingDialog.show();
            isShowing = true;
        }

    }

    public boolean isShowing(){
        return isShowing;
    }
}

你可能感兴趣的:(Android学习笔记,dialog)