Android自定义的弹窗

package com.microduino.qoobot.view;

import android.app.Activity;
import android.app.Dialog;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;

import com.microduino.qoobot.R;

/*
 * :Created by z on 2019/1/16
 */

public abstract class BaseDialog {
    
    private Dialog dialog;
    private Activity activity;
    
    public BaseDialog(Activity activity,int res){
        
        dialog = new Dialog(activity, R.style.BuildDialog);
        LayoutInflater inflater = LayoutInflater.from(activity);
        View view = inflater.inflate(res, null);
        initView(view);
        
        initWindow();
        
        dialog.setContentView(view);
        dialog.setCanceledOnTouchOutside(true);
    }
    
    private void initWindow() {
        Window window = dialog.getWindow();
        window.setGravity(Gravity.BOTTOM); //可设置dialog的位置
        window.getDecorView().setPadding(0, 0, 0, 0); //消除边距

        //设置去除dialog中的系统状态栏
        window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

        // window.setWindowAnimations(R.style.dialog_anima);

        WindowManager.LayoutParams layoutParams = window.getAttributes();
        layoutParams.width = WindowManager.LayoutParams.MATCH_PARENT;   //设置宽度充满屏幕
        layoutParams.height = WindowManager.LayoutParams.MATCH_PARENT;
        window.setAttributes(layoutParams);
    }
    
    public abstract void initView(View view);
    
    public void showDialog() {
        if (dialog != null) {
            dialog.show();
        }
    }

    public void dismissDialog() {
        if (dialog != null && dialog.isShowing()) {
            dialog.dismiss();
            //dialog = null;
        }

    }
    
}

 

转载于:https://www.cnblogs.com/Oldz/p/10278786.html

你可能感兴趣的:(Android自定义的弹窗)