Android How to implement Bottom Sheet from Material Design docs

后端 未结 7 2460
一向
一向 2020-11-28 01:50

How do you implement the bottom sheet specficiation? http://www.google.com/design/spec/components/bottom-sheets.html

The new update to Google Drive shows this with

7条回答
  •  误落风尘
    2020-11-28 02:00

    Following the blog post: http://android-developers.blogspot.com/2016/02/android-support-library-232.html

    My xml ended up looking like this:

    
        
            
        
    
    

    And in my onCreateView of my fragment:

        coordinatorLayout = (CoordinatorLayout)v.findViewById(R.id.coordinator_layout);
        View bottomSheet = coordinatorLayout.findViewById(R.id.bottom_sheet);
        BottomSheetBehavior behavior = BottomSheetBehavior.from(bottomSheet);
        behavior.setPeekHeight(100);
        behavior.setBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() {
            @Override
            public void onStateChanged(@NonNull View bottomSheet, int newState) {
                // React to state change
            }
    
            @Override
            public void onSlide(@NonNull View bottomSheet, float slideOffset) {
                // React to dragging events
            }
        });
    

    The default of setPeekHeight is 0, so if you don't set it, you won't be able to see your view.

提交回复
热议问题