Android How to implement Bottom Sheet from Material Design docs

后端 未结 7 2423
一向
一向 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:07

    Edit

    The BottomSheet is now part of the android-support-library. See John Shelleys' answer.


    Unfortunately there's currently no "official" way on how to do this (at least none that I'm aware of).
    Luckily there's a library called "BottomSheet" (click) which mimics the look and feel of the BottomSheet and supports Android 2.1 and up.

    In case of the Drive app, here's how the code would look like with this library:

        new BottomSheet.Builder(this, R.style.BottomSheet_Dialog)
                .title("New")
                .grid() // <-- important part
                .sheet(R.menu.menu_bottom_sheet)
                .listener(new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                // TODO
            }
        }).show();
    

    menu_bottom_sheet (basically a standard /res/menu/*.xml resource)

    
        
        
        
    
    

    Output looks like this:

    picture of the bottom sheet

    Which, I think, comes pretty close to the original. If you're not happy with the colors you can customize it - see this (click).

提交回复
热议问题