content: package com.zht.baseproject.base;
  
  import android.app.Dialog;
  import android.os.Bundle;
  import android.support.annotation.Nullable;
  import android.support.v4.app.DialogFragment;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.ViewGroup;
  import android.view.Window;
  
  import com.zht.baseproject.R;
  
  /**
   * Created by ZHT on 2017/4/18.
   * DialogFragment基类
   * 用于显示背景透明的DialogFragment
   */
  
  public abstract class BaseDialogFragment extends DialogFragment {
  
      private View mView;
  
      @Override
      public void onStart() {
          super.onStart();
          Dialog dialog = getDialog();
          Window window = dialog == null ? null : dialog.getWindow();
          if (null != dialog && null != window) {
              window.setLayout(-1, -2);
          }
      }
  
      @Override
      public void onCreate(@Nullable Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setStyle(STYLE_NORMAL, R.style.dialog);  //具有阴影效果
      }
  
      @Nullable
      @Override
      public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
  
          mView = inflater.inflate(getLayoutId(), null);
  
          getDialog().requestWindowFeature(Window.FEATURE_NO_TITLE); //去除标题栏
  
          /*// 设置宽度为屏宽、居中。
          Window window = getDialog().getWindow();
          WindowManager.LayoutParams params = window.getAttributes();
          params.gravity = Gravity.CENTER;*/
  
          return mView;
      }
  
      @Override
      public void onActivityCreated(Bundle savedInstanceState) {
          super.onActivityCreated(savedInstanceState);
          afterCreate(savedInstanceState);
      }
  
      protected abstract int getLayoutId();
  
      protected abstract void afterCreate(Bundle savedInstanceState);
  }
  