title: Sometimes BottomSheetDialogFragment opens in center of screen like alert dialog
body: <p>I have BottomSheetDialogFragment which required to open in expanded state and should skip collapsed state while swipedown.</p>
  <p>The problem is, I get unexpected behavior sometimes</p>
  <p><a href="https://i.stack.imgur.com/4x34d.png" rel="noreferrer"><img src="https://i.stack.imgur.com/4x34d.png" alt="Unexpected Behavior" /></a></p>
  <p>Why I am getting this kind of view sometimes?</p>
  <p>here below is my code for that,</p>
  <pre><code>@Override
      public int getTheme() {
          if (Build.VERSION.SDK_INT &gt; 21) {
              return R.style.BottomSheetDialogTheme;
          } else {
              return super.getTheme();
          }
      }
  
      @NonNull
      @Override
      public Dialog onCreateDialog(Bundle savedInstanceState) {
  
          BottomSheetDialog dialog = (BottomSheetDialog) super.onCreateDialog(savedInstanceState);
  
          dialog.setOnShowListener((DialogInterface.OnShowListener) dialog1 -&gt; {
              BottomSheetDialog d = (BottomSheetDialog) dialog1;
              FrameLayout bottomSheet = (FrameLayout) d.findViewById(com.google.android.material.R.id.design_bottom_sheet);
              if (bottomSheet != null) {
                  BottomSheetBehavior.from(bottomSheet).setState(BottomSheetBehavior.STATE_EXPANDED);
                  BottomSheetBehavior.from(bottomSheet).setSkipCollapsed(true);
                  BottomSheetBehavior.from(bottomSheet).setFitToContents(true);
                  BottomSheetBehavior.from(bottomSheet).setPeekHeight(1000);
              }
          });
  
          return dialog;
      }
  </code></pre>
  <p>And style/theming for the same is</p>
  <pre><code>     &lt;style name=&quot;BottomSheetDialogTheme&quot; parent=&quot;BaseBottomSheetDialog&quot;&gt;
              &lt;item name=&quot;android:statusBarColor&quot; tools:targetApi=&quot;lollipop&quot;&gt;@android:color/transparent
              &lt;/item&gt;
          &lt;/style&gt;
          &lt;!-- set the rounded drawable as background to your bottom sheet --&gt;
          &lt;style name=&quot;BottomSheet&quot; parent=&quot;@style/Widget.Design.BottomSheet.Modal&quot;&gt;
              &lt;item name=&quot;android:background&quot;&gt;@drawable/bottomsheet_round_corner_bg&lt;/item&gt;
          &lt;/style&gt;
      
          &lt;style name=&quot;BaseBottomSheetDialog&quot; parent=&quot;@style/Theme.Design.Light.BottomSheetDialog&quot;&gt;
              &lt;item name=&quot;android:windowIsFloating&quot;&gt;false&lt;/item&gt;
              &lt;item name=&quot;bottomSheetStyle&quot;&gt;@style/BottomSheet&lt;/item&gt;
              &lt;item name=&quot;android:windowSoftInputMode&quot;&gt;adjustResize&lt;/item&gt;
          &lt;/style&gt;
  </code></pre>
  <p>Mostly I achieve this part but somehow other screenshot behavior appears.
  <a href="https://i.stack.imgur.com/J6VJu.png" rel="noreferrer"><img src="https://i.stack.imgur.com/J6VJu.png" alt="Expected Behavior" /></a></p>
  <p>Anyone have solve or faced this issue can comment or answer solution,
  thank you.</p>