【问题标题】:How to dim background when using the BottomSheet from the support library?使用支持库中的 BottomSheet 时如何使背景变暗?
【发布时间】:2016-10-21 15:23:05
【问题描述】:

如何像here 显示的那样使背景变暗?

我已正常使用CoordinatorLayoutBottomSheetBehavior 进行设置。

【问题讨论】:

    标签: android android-coordinatorlayout androiddesignsupport bottom-sheet


    【解决方案1】:

    这将简单地显示一个底部工作表。

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

    【讨论】:

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

      【讨论】:

        【解决方案3】:

        使用BottomSheetDialog

        基本上它是一个对话框(即支持暗淡)并支持模态底部工作表行为尝试一下

        【讨论】:

        • 不剪。需要BottomSheetDialogFragment,因为普通对话框不能全屏。
        猜你喜欢
        • 2014-06-06
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多