Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to dim background when using the BottomSheet from the support library?

How can the background be dimmed just like it is shown here?

I've set it up normally using the CoordinatorLayout and the BottomSheetBehavior.

like image 444
Niklas Avatar asked Jun 20 '16 11:06

Niklas


2 Answers

    bottomSheetBehavior.addBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() {
                @Override
                public void onStateChanged(@NonNull View bottomSheet, int newState) {}

                @Override
                public void onSlide(@NonNull View bottomSheet, float slideOffset) {

                            (your_layout/view).setAlpha(1 - slideOffset);

                }
            });
like image 43
SardorbekR Avatar answered Oct 16 '22 11:10

SardorbekR


This will simply show a bottom sheet.

public class MyBottomSheet extends BottomSheetDialogFragment {
    private static final String TAG = "MyBottomSheet";

    @NonNull
    @Override
    public Dialog onCreateDialog(final Bundle savedInstanceState) {
        final BottomSheetDialog dialog = (BottomSheetDialog) super.onCreateDialog(savedInstanceState);

        final View view = View.inflate(getContext(), R.layout.my_custom_view, null);

        dialog.setContentView(view);
        behavior = BottomSheetBehavior.from((View) view.getParent());

        return dialog;
    }

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

To close the dialog simply as normal call close().

like image 161
Niklas Avatar answered Oct 16 '22 11:10

Niklas