Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 UI. Is there anyway this can be achieved?

like image 623
atabouraya Avatar asked Jun 02 '16 15:06

atabouraya


2 Answers

public class BottomSheetDimmedFragment extends BottomSheetDialogFragment {
    public static final String TAG = BottomSheetDimmedFragment.class.getSimpleName();

    @NonNull
    @Override
    public Dialog onCreateDialog(final Bundle savedInstanceState) {
        final BottomSheetDialog dialog = (BottomSheetDialog) super.onCreateDialog(savedInstanceState);
        final View view = View.inflate(getContext(), R.layout.test, null);
        dialog.setContentView(view);
        return dialog;
    }

    public void show(final FragmentActivity fragmentActivity) {
        show(fragmentActivity.getSupportFragmentManager(), TAG);
    }
}

In your activity:

BottomSheetDimmedFragment sheet = new BottomSheetDimmedFragment();
sheet.show(this);

Now, you will have a dim and also when clicked on a dim the dialog will close.

enter image description here

Implementation taken from here.

like image 173
azizbekian Avatar answered Oct 16 '22 14:10

azizbekian


Use the bottom sheet with a fragment instead of a view :)

like image 34
Vaigunth Avatar answered Oct 16 '22 14:10

Vaigunth