【问题标题】:Dim Screen and Block Interaction with BottomSheets暗屏并阻止与 BottomSheets 的交互
【发布时间】:2016-06-02 15:54:18
【问题描述】:

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

【问题讨论】:

    标签: android android-layout android-fragments android-view bottom-sheet


    【解决方案1】:
    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);
    

    现在,您将有一个暗淡,当点击一个暗淡时,对话框也会关闭。

    实现取自here

    【讨论】:

      【解决方案2】:

      使用带有片段而不是视图的底部工作表:)

      【讨论】:

        【解决方案3】:

        注意有两种实现方式:

        BottomSheetBehaviorBottomSheetDialogFragment

        使用BottomSheetDialogFragment 获取您需要的功能。

        当使用BottomSheetBehavior 时,设置布局的android:clickable="true"。这样,当您点击空白区域时,点击不会通过。 (为了清楚起见:在包含标签app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior"的布局上设置了可点击)

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2021-05-08
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2013-01-11
          相关资源
          最近更新 更多