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

送分小仙女□ 提交于 2019-12-09 16:38:00

问题


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

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


回答1:


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().




回答2:


use BottomSheetDialog

basically it's a dialog (i.e support dim) and support modal bottom sheets behaviour give it a try



来源:https://stackoverflow.com/questions/37921368/how-to-dim-background-when-using-the-bottomsheet-from-the-support-library

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!