Dialog基类封装-----自定义dialog

 该封装类用于dialog中有比较多的业务逻辑



import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.view.LayoutInflater;
import android.view.View;

/**
 * @author xianyong dai
 * @version v1.0
 * @Title: BaseDialog
 * @Description:对话框封装类
 * @date 2018/12/4 16:20
 */
public abstract class BaseDialog extends Dialog {


    public BaseDialog(@NonNull Context context) {
        super(context);
    }

    public BaseDialog(@NonNull Context context, int themeResId) {
        super(context, themeResId);
    }
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        LayoutInflater inflater = LayoutInflater.from(getContext());
        View view = inflater.inflate(getLayoutId(), null);
        setContentView(view);
        initView(view);
        initData();
        initListener();
    }


    protected abstract int getLayoutId();

    protected abstract void  initView(View view);

    protected abstract void initData();

    protected abstract void initListener();

    protected abstract void setLayoutSize();

    @Override
    public void show() {
        super.show();
        setLayoutSize();//在show之后设置布局宽高
    }


}

 

你可能感兴趣的:(android)