使用BottomSheetDialog创建底部弹窗

BottomSheetBehavior 和 BottomSheetDialog都是design包里的。这两种配合使用可以实现底部弹窗效果。
BottomSheetDialog使用方法和正常的弹框是一样的,他的内部是通过BottomSheetBehavior来控制弹框的收起和弹出等状态。
BottomSheetBehavior的状态:

/**
     * The bottom sheet is dragging.
     */
    public static final int STATE_DRAGGING = 1;

    /**
     * The bottom sheet is settling.
     */
    public static final int STATE_SETTLING = 2;

    /**
     * The bottom sheet is expanded.
     */
    public static final int STATE_EXPANDED = 3;

    /**
     * The bottom sheet is collapsed.
     */
    public static final int STATE_COLLAPSED = 4;

    /**
     * The bottom sheet is hidden.
     */
    public static final int STATE_HIDDEN = 5;

使用方法

if (sheetDialog == null) {
   sheetDialog = new BottomSheetDialog(getContext());
   sheetDialog.setContentView(recyclerView);
   View view1 = sheetDialog.getDelegate().findViewById(android.support.design.R.id.design_bottom_sheet);
   final BottomSheetBehavior bottomSheetBehavior = BottomSheetBehavior.from(view1);
   bottomSheetBehavior.setBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() {
       @Override
       public void onStateChanged(@NonNull View bottomSheet, int newState) {
           if (newState == BottomSheetBehavior.STATE_HIDDEN) {
               sheetDialog.dismiss();
               bottomSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
           }
        }

        @Override
        public void onSlide(@NonNull View bottomSheet, float slideOffset) {

        }
    });
}
sheetDialog.show();

http://blog.csdn.net/u010198148/article/details/53670629

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容