在支持库中使用BottomSheet时如何调暗背景? [英] How to dim background when using the BottomSheet from the support library?

查看:278
本文介绍了在支持库中使用BottomSheet时如何调暗背景?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何像显示背景一样将背景变暗这里?

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

我通常使用CoordinatorLayoutBottomSheetBehavior对其进行设置.

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

推荐答案

这将仅显示一个底页.

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);
    }
}

要像平常一样直接调用close()来关闭对话框.

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

这篇关于在支持库中使用BottomSheet时如何调暗背景?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆