屏幕变暗并与BottomSheets互动 [英] Dim Screen and Block Interaction with BottomSheets

查看:103
本文介绍了屏幕变暗并与BottomSheets互动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

BottomSheetBehavior已在Android设计支持库23.2中引入,但是它不会使屏幕的其余部分变暗,也不会阻止与UI的其余部分的交互.无论如何,这可以实现吗?

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?

推荐答案

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

在您的活动中:

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

现在,您将看到一个暗淡的颜色,并且当单击一个暗淡的颜色时,对话框也会关闭.

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

实施摘自此处.

这篇关于屏幕变暗并与BottomSheets互动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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