title: Prevent dismissal of BottomSheetDialogFragment on touch outside
body: <p>I have implemented a BottomSheet Dialog and I want to prevent the bottomsheet from dismissing when the user touches outside of the bottomsheet when it's peeking (Not fully expanded state).</p>
  
  <p>I have set <code>dialog.setCanceledOnTouchOutside(false);</code> in the code but it doesn't seem to take any affect.</p>
  
  <p>Here's my BottomSheetDialogFragment class:</p>
  
  <pre><code>public class ShoppingCartBottomSheetFragment extends BottomSheetDialogFragment  {
  
      private BottomSheetBehavior.BottomSheetCallback mBottomSheetBehaviorCallback = new BottomSheetBehavior.BottomSheetCallback() {
  
          @Override
          public void onStateChanged(@NonNull View bottomSheet, int newState) {
              if (newState == BottomSheetBehavior.STATE_HIDDEN) {
                  dismiss();
              }
  
          }
  
          @Override
          public void onSlide(@NonNull View bottomSheet, float slideOffset) {
          }
      };
  
      @Override
      public void setupDialog(Dialog dialog, int style) {
          super.setupDialog(dialog, style);
  
          View contentView = View.inflate(getContext(), R.layout.fragment_shopping_cart_bottom_sheet, null);
  
          dialog.setCanceledOnTouchOutside(false);
  
          dialog.setContentView(contentView);
  
          CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) ((View) contentView.getParent()).getLayoutParams();
          CoordinatorLayout.Behavior behavior = params.getBehavior();
  
          if( behavior != null &amp;&amp; behavior instanceof BottomSheetBehavior ) {
              ((BottomSheetBehavior) behavior).setBottomSheetCallback(mBottomSheetBehaviorCallback);
              ((BottomSheetBehavior) behavior).setPeekHeight(97);
              ((BottomSheetBehavior) behavior).setHideable(false);
          }
      }
  
  
      @Override
      public void onStart() {
          super.onStart();
          Window window = getDialog().getWindow();
          WindowManager.LayoutParams windowParams = window.getAttributes();
          windowParams.dimAmount = 0;
          windowParams.flags |= WindowManager.LayoutParams.FLAG_DIM_BEHIND;
          window.setAttributes(windowParams);
      }
  }
  </code></pre>
  
  <p>According to the BottomSheet <a href="https://material.io/guidelines/components/bottom-sheets.html#bottom-sheets-behavior" rel="noreferrer">specification</a> bottom sheets can be dismissed by touching outside of the bottom sheet, therefore what are my options to override this behavior and prevent it being dismissed?</p>