美文网首页Android功能代码
Android dialog设置充满全屏

Android dialog设置充满全屏

作者: cc_And | 来源:发表于2024-02-28 15:21 被阅读0次
      <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;
      }
    }
    

    相关文章

      网友评论

        本文标题:Android dialog设置充满全屏

        本文链接:https://www.haomeiwen.com/subject/bpcfzdtx.html