<style name="FullScreenDialogTheme" parent="Theme.AppCompat.Dialog">
<!-- 上面说过,只要是Dialog,这两个属性必须设置 -->
<item name="android:windowIsFloating">false</item>
<item name="android:windowBackground">@android:color/transparent</item>
<!--设置透明状态栏,适用于SDK19(4.4)及以上版本-->
<item name="android:windowTranslucentStatus" >true</item>
<!-- 如果你不需要自定义状态栏颜色,下面两个可不要 -->
<item name="android:windowDrawsSystemBarBackgrounds" >true</item>
<item name="android:statusBarColor">@android:color/transparent</item>
<!-- 透明导航栏 -->
<item name="android:windowTranslucentNavigation">true</item>
</style>
public class FullPhotoDialog extends DialogFragment {
@NonNull
@NotNull
@Override
public Dialog onCreateDialog(@Nullable @org.jetbrains.annotations.Nullable Bundle savedInstanceState) {
setStyle(STYLE_NORMAL, R.style.FullScreenDialogTheme);
Dialog dialog = super.onCreateDialog(savedInstanceState);
Window window = dialog.getWindow();
window.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
window.getDecorView().setPadding(0, 0, 0, 0);
WindowManager.LayoutParams layoutParams = window.getAttributes();
layoutParams.width = WindowManager.LayoutParams.MATCH_PARENT;
layoutParams.height = WindowManager.LayoutParams.MATCH_PARENT;
return dialog;
}
}
网友评论