Dim Screen And Block Interaction With Bottomsheets
BottomSheetBehavior has been introduced in Android Design Support Library 23.2, however it does not dim the rest of the screen and does not block interaction with the rest of the U
Solution 1:
publicclassBottomSheetDimmedFragmentextendsBottomSheetDialogFragment {
publicstaticfinalStringTAG= BottomSheetDimmedFragment.class.getSimpleName();
@NonNull@Overridepublic Dialog onCreateDialog(final Bundle savedInstanceState) {
finalBottomSheetDialogdialog= (BottomSheetDialog) super.onCreateDialog(savedInstanceState);
finalViewview= View.inflate(getContext(), R.layout.test, null);
dialog.setContentView(view);
return dialog;
}
publicvoidshow(final FragmentActivity fragmentActivity) {
show(fragmentActivity.getSupportFragmentManager(), TAG);
}
}
In your activity:
BottomSheetDimmedFragmentsheet=newBottomSheetDimmedFragment();
sheet.show(this);
Now, you will have a dim and also when clicked on a dim the dialog will close.
Implementation taken from here.
Solution 2:
Use the bottom sheet with a fragment instead of a view :)
Solution 3:
Note that there are two implementations:
BottomSheetBehaviorandBottomSheetDialogFragment.
Use BottomSheetDialogFragment to get the functionality you need.
Also when using BottomSheetBehavior set the layout's android:clickable="true". That way clicks don't go through when you click on empty space. (For clarity: clickable is set on the layout containing the tag app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior")

Post a Comment for "Dim Screen And Block Interaction With Bottomsheets"