自定义dialog

public class Dialog_Coupon extends DialogFragment {
    Unbinder unbinder;
    private View view;
    /**
    * 点击回调类
    */
    private OnDialogListener onDialogListener;
  //防空判断
    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
        if (onDialogListener == null) {
            dismiss();
        }  
  }
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        getDialog().requestWindowFeature(Window.FEATURE_NO_TITLE);
        //背景透明。不设置该属性圆角会出现白边
        getDialog().getWindow().setBackgroundDrawable(new  ColorDrawable(Color.TRANSPARENT));
        getDialog().getWindow().getAttributes().windowAnimations = R.style.dialogOpenAndClose;
        view = inflater.inflate(R.layout.dialog_coupon, null);
        unbinder = ButterKnife.bind(this, view);
        return view;
    }
    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        //点击空白处不可取消
        getDialog().setCancelable(false);
    }
    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }
    /**
    * 点击事件集合
    */
    @OnClick({R.id.bt_use})
    public void onViewClicked(View view) {
        switch (view.getId()) {
//XXXXXXX
                  }
    }
    public interface OnDialogListener {
        void clickUse();
    }
    public void setOnDialogListent(OnDialogListener onDialogListener) {
        this.onDialogListener = onDialogListener;
    }
}

你可能感兴趣的:(自定义dialog)