1、在styles.xml里加上

1
2
3
4
5
<style name="dialog_fullscreen" parent="@android:style/Theme.Translucent.NoTitleBar">
<item name="android:windowTranslucentStatus">true</item>
<!--自定义透明度-->
<item name="android:windowBackground">@color/black_30</item>
</style>

2、建一个DialogFragment

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
public class BaseDialogFragment extends DialogFragment {
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setStyle(DialogFragment.STYLE_NO_TITLE, R.style.dialog_fullscreen);

}

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
//自定义布局
return inflater.inflate(R.layout.dialog_share, null);
}
}