One way to present a set of actions to a user is with bottom sheets, a sheet of paper that slides up from the bottom edge of the screen. Bottom sheets offer flexibility in the display of clear and simple actions that do not need explanation.

Related tags

Menu BottomSheet
Overview

BottomSheet

Build Status Android Arsenal

Google introduced official bottomsheets implementation in Support library 23.2.0,thus this library is no longer activly being developed. I will continuely fix defects been found and accept good PR but No more new feature will be developed. Thanks for your support!

One way to present a set of actions to a user is with bottom sheets, a sheet of paper that slides up from the bottom edge of the screen. Bottom sheets offer flexibility in the display of clear and simple actions that do not need explanation.

https://www.google.com/design/spec/components/bottom-sheets.html

This library works on android api 14+

Sample Sample Sample Sample Sample Sample

How to use this library

  • Download this library, import to your IDE (eclipse...) as a library project.
  • Using Gradle
    compile 'com.cocosw:bottomsheet:1.+@aar'
  • Using Maven
<dependency>
    <groupId>com.cocosw</groupId>
    <artifactId>bottomsheet</artifactId>
    <version>1.x</version>
    <type>apklib</type>
</dependency>
  • Version if you use Android support library - 1.4.0 if you use Androidx - 1.5.0

API

  • Define actions in menu xml (Tip: divider tag has been replaced by group tag from 1.1.0)
<menu xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:id="@+id/share" android:title="@string/share" android:icon="@drawable/perm_group_messages"/>
    <item android:id="@+id/upload" android:title="@string/upload" android:icon="@drawable/perm_group_system_clock"/>
    <item android:id="@+id/call" android:title="@string/call" android:icon="@drawable/perm_group_phone_calls"/>
    <group android:id="@+id/helpgroup">
         <item android:id="@+id/help" android:title="@string/help" android:icon="@drawable/perm_group_system_tools"/>
    </group>
</menu>
  • Show it just like showing a dialog.
new BottomSheet.Builder(this).title("title").sheet(R.menu.list).listener(new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        switch (which) {
                            case R.id.help:
                                q.toast("Help me!");
                                break;
                        }
                    }
                }).show();
  • You can also add action items in builder.

Action items manipulate

You can get a menu object from bottomsheet instance from 1.1.0, and change it as you want, exactly like you're manipulating an android menu or actionbar actionitems. Please be aware that if you change the menu after showing the bottomsheet, you must call invalidate(), or no changes will be applied and your app might crash. Please check example application for more info.

Style

  • Invoke darkTheme() to show the built-in dark theme
  • Or define your style in your application, and call bottomsheet by using new BottomSheet.Builder(this,R.style.BottomSheet_StyleDialog)....
    <style name="BottomSheet.StyleDialog" parent="BottomSheet.Dialog">
        <item name="android:backgroundDimAmount">0.5</item>
        <item name="android:windowAnimationStyle">@style/BottomSheet.Animation</item>
        <item name="android:textColorPrimary">#DDffffff</item>
        <item name="android:textColorSecondary">#8Affffff</item>
        <item name="android:textColorHint">#42ffffff</item>
        <item name="bs_dialogBackground">@color/abc_search_url_text_normal</item>
        <item name="bs_dividerColor">@color/abc_search_url_text_pressed</item>
        <item name="bs_numColumns">4</item>
        <item name="bs_listStyle">@style/BottomSheet.StyleList</item>
    </style>
  • Or set bottomesheet style in your activity theme
    <style name="StyleTheme" parent="Theme.AppCompat">
        <item name="bs_bottomSheetStyle">@style/BottomSheet.StyleDialog</item>
    </style>

Contribute

  • Feel free to fork it

About me

I'm Kai, an 32 years old android developer based in Sydney.

License

Copyright 2011, 2015 Kai Liao

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Comments
  • Make BottomSheet.List layout animation configurable

    Make BottomSheet.List layout animation configurable

    In the current version it is possible to change the animation for the dialog as whole, however, it not possible to change the layout animation for the BottomSheet.List. It would be nice if it was a styleable attr.

    opened by EmileEmile 21
  • Error when swipe down

    Error when swipe down

    When I swipe down with this menu I get the following error:

    Attempting to destroy the window while drawing!

    When I try to click on my Button to show the dialog again it doesn't show, the screen simply flashes black for a split second. When I click on the Button again it shows properly. The only way I was able to get this to work is by doing this for canceling:

    closeOptionsMenu() and sheet.setCanceledOnSwipeDown(false);

    Is there a way to get the swipe down working properly?

    opened by kalvish21 14
  • Allowing own View and own Adapters with RecyclerView

    Allowing own View and own Adapters with RecyclerView

    For more flexibility this would allow to use this library in more or less any case. For example in my app I need to be able to show a variable list of items depending on the current state of the app.

    • Allow usage of RecyclerView (we get better Lists and Grids!)
    • Allow Custom Adapters
    • Allow setting own View
    • Adjust callbacks for above (maybe multiple callbacks or custom callbacks?)

    I will most likely start working on this soon :). If you have any things you want to tell me to do while doing it, or what to watch out for, please let me know. Of course I will send a pull request in the end.

    This might go into the same pull request as #24 because it will probably as well change the Dialog to a DialogFragment.

    opened by pboos 14
  • Attribute

    Attribute "bottomSheetStyle" has already been defined

    The latest support library version (23.2.0) adds Google's own variety of BottomSheets and unfortunately there is name clash on the style attribute when you have both libraries as dependencies meaning the app fails to compile.

    opened by stephenmcbride 13
  • Make the Sheet scrollable

    Make the Sheet scrollable

    Currently when in Landscape mode the sheet quickly fills up the entire screen. Even worse, some action items are cut off. I could go to Grid mode, but on small screens even that won't help.

    opened by kashban 9
  • maxWidth option

    maxWidth option

    Hi,

    could you add an option to set the maxWidth of the BottomSheet. Right now, on landscape mode it fill up the whole screen. I would like it to be more narrow (just like the menu options)

    thanks

    opened by gnuhel 8
  • AbstractMethodError on Android O

    AbstractMethodError on Android O

    Hey, i'm using the latest Android O version on Pixel

    happens everytime i try to open it

    E/AndroidRuntime: FATAL EXCEPTION: main Process: com.tnx.apps.coinportfolio, PID: 2885 java.lang.AbstractMethodError: abstract method "android.view.MenuItem android.support.v4.internal.view.SupportMenuItem.setAlphabeticShortcut(char, int)" at android.view.MenuInflater$MenuState.setItem(MenuInflater.java:477) at android.view.MenuInflater$MenuState.addItem(MenuInflater.java:541) at android.view.MenuInflater.parseMenu(MenuInflater.java:193) at android.view.MenuInflater.inflate(MenuInflater.java:114) at com.cocosw.bottomsheet.BottomSheet$Builder.sheet(BottomSheet.java:531) at com.tnx.apps.coinportfolio.activity.ManageTransactionsActivity$MyAdapter$1.onClick(ManageTransactionsActivity.java:126) at android.view.View.performClick(View.java:6256) at android.view.View$PerformClick.run(View.java:24697) at android.os.Handler.handleCallback(Handler.java:789) at android.os.Handler.dispatchMessage(Handler.java:98) at android.os.Looper.loop(Looper.java:164) at android.app.ActivityThread.main(ActivityThread.java:6541) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)

    opened by AlexanderThiele 7
  • Swipe up and down

    Swipe up and down

    I would suggest the following well known and widely used solution instead of the ClosableSlidingLayoutyou now have (actually, the horizontal swipe could be removed from it completely). This handles the swipe easily and nicely and could be used for both directions, to open up from More and to close down:

    public class SwipeFrameLayout extends android.widget.FrameLayout {
      private final GestureDetector gestureDetector;
      protected OnHorizontalSwipe horizontalListener;
      protected OnVerticalSwipe verticalListener;
    
      public interface OnHorizontalSwipe {
        public boolean onSwipeLeft();
    
        public boolean onSwipeRight();
      }
    
      public interface OnVerticalSwipe {
        public boolean onSwipeUp();
    
        public boolean onSwipeDown();
      }
    
      public SwipeFrameLayout(Context context) {
        super(context);
        gestureDetector = new GestureDetector(context, new GestureListener());
      }
    
      public SwipeFrameLayout(Context context, AttributeSet attrs) {
        super(context, attrs);
        gestureDetector = new GestureDetector(context, new GestureListener());
      }
    
      public SwipeFrameLayout(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        gestureDetector = new GestureDetector(context, new GestureListener());
      }
    
      @Override
      public boolean dispatchTouchEvent(MotionEvent e) {
        gestureDetector.onTouchEvent(e);
        return super.dispatchTouchEvent(e);
      }
    
      public void setHorizontalListener(OnHorizontalSwipe horizontalListener) {
        this.horizontalListener = horizontalListener;
      }
    
      public void setVerticalListener(OnVerticalSwipe verticalListener) {
        this.verticalListener = verticalListener;
      }
    
      private final class GestureListener extends SimpleOnGestureListener {
        private static final int SWIPE_DISTANCE_THRESHOLD = 100;
        private static final int SWIPE_VELOCITY_THRESHOLD = 100;
    
        @Override
        public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
          float dX = e2.getX() - e1.getX();
          float dY = e2.getY() - e1.getY();
          if (Math.abs(dX) > Math.abs(dY) && Math.abs(dX) > SWIPE_DISTANCE_THRESHOLD && Math.abs(velocityX) > SWIPE_VELOCITY_THRESHOLD) {
            if (dX > 0) {
              if (horizontalListener != null)
                return horizontalListener.onSwipeRight();
            }
            else {
              if (horizontalListener != null)
                return horizontalListener.onSwipeLeft();
            }
          }
          else if (Math.abs(dY) > Math.abs(dX) && Math.abs(dY) > SWIPE_DISTANCE_THRESHOLD && Math.abs(velocityY) > SWIPE_VELOCITY_THRESHOLD) {
            if (dY > 0) {
              if (verticalListener != null)
                return verticalListener.onSwipeDown();
            }
            else {
              if (verticalListener != null)
                return verticalListener.onSwipeUp();
            }
          }
          return false;
        }
      }
    
    }
    
    opened by deakjahn 7
  • Option to disable menu options floating in animation

    Option to disable menu options floating in animation

    Setting windowAnimationStyle to @null didn't seem to have any effect. I would like to disable the items in the bottom sheet "floating in" at different speeds without disabling the slide in animation on the bottom sheet, to match the Android Lollipop share intent animation and Google Drive's bottom sheet.

    opened by vemacs 6
  • Checkable Bottom Sheet

    Checkable Bottom Sheet

    Hi,

    What's the recommended way to show a checkable menu as a Bottom Sheet? I've tried using the default as described here, and the radio buttons don't show up. Thanks.

    opened by Gregliest 5
  • Minimize instead of close sheet

    Minimize instead of close sheet

    Hi, in your sample, when I view a Style from Theme sheet, sheets slide up correctly. Then when I click more, the sheet slides up to full screen. However, after that there is no way to minimize it back down to previous size. Instead, it closes completely when I slide it down.

    Please advise, Igor

    opened by IgorGanapolsky 5
  • Implement more robust NavigationarHeight computation

    Implement more robust NavigationarHeight computation

    Previously the navbar height would be 0 for my Oneplus One (Android 7.1), so I interchanged your navBarHeight code for mine. :D Now it gives the correct padding again.

    opened by JWvanV 0
  • Behind navigation bar

    Behind navigation bar

    Hey, nice library. I do see something wierd with a transparent navigation bar. On my Nexus7 the sheet does the correct thing and adds padding to the sheet bottom. On my OneplusOne the sheet doesn't do the correct thing and make the sheet overlap with the navigation bar :(

    My statusbar height implementation works on all my activities. Could you compare it with yours?

        private static boolean hasNavBar(Context context) {
            // Kitkat and less shows container above nav bar
            if (android.os.Build.VERSION.SDK_INT <= Build.VERSION_CODES.KITKAT) {
                return false;
            }
            // Emulator
            if (Build.FINGERPRINT.startsWith("generic")) {
                return true;
            }
            boolean hasMenuKey = ViewConfiguration.get(context).hasPermanentMenuKey();
            boolean hasBackKey = KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_BACK);
            boolean hasNoCapacitiveKeys = !hasMenuKey && !hasBackKey;
            Resources resources = context.getResources();
            int id = resources.getIdentifier("config_showNavigationBar", "bool", "android");
            boolean hasOnScreenNavBar = id > 0 && resources.getBoolean(id);
            return hasOnScreenNavBar || hasNoCapacitiveKeys || getNavigationBarHeight(context, true) > 0;
        }
    
        public static int getNavigationBarHeight(Context context, boolean skipRequirement) {
            int resourceId = context.getResources().getIdentifier("navigation_bar_height", "dimen", "android");
            if (resourceId > 0 && (skipRequirement || hasNavBar(context))) {
                return context.getResources().getDimensionPixelSize(resourceId);
            }
            return 0;
        }
    
    opened by JWvanV 3
  • Bug: Icons are blurry in grid view

    Bug: Icons are blurry in grid view

    We're using Material Design icons from the Google library, at 48dp.

    When using list style, the icons look great.

    When using grid style, the icons are blurry on various tablets, but not on phones. I get the same result whether I build the Bottom sheet using items defined in a menu XML file, or dynamically from code (using enum values).

    Overview blurry_icons_overview

    Up Close blurry_icons_magnified

    Should @style/BottomSheet_GridItemImage just use wrap_content for layout_width and layout_height instead of explicitly specifying 48dp?

    opened by ajhuntsman 4
Suhuf is an android library that is used to build bottom sheets in an elegant way.

Suhuf is an android library that is used to build bottom sheets in an elegant way.

Rahmat Rasyidi Hakim 10 Nov 15, 2021
Bottom Sheet fragment with a sticky header and a content recycler view

Sticky Header Bottom Sheet A simple library to create a Bottom Sheet with a sticky header and a content recycler view. The bottom sheet expands on scr

Kshitij Kumar 12 Sep 21, 2022
You can create awesome menus with bottom sheet experience in a few lines

You can create awesome menus with bottom sheet experience in a few lines

Mazen Rashed 19 Nov 1, 2022
Spinner with bottom sheet dialog for Android

This is a small library for spinner view with displaying options in bottom sheet dialog. This view doesn't improve or extend the default android Spinner. The library doesn't support any other types of showing menu, only bottom sheet dialog.

Oleg Nestyuk 23 Oct 19, 2022
Android library that provides the floating action button to sheet transition from Google's Material Design.

MaterialSheetFab Library that implements the floating action button to sheet transition from Google's Material Design documentation. It can be used wi

Gordon Wong 1.6k Dec 13, 2022
Bottom Navigation widget component inspired by the Google Material Design Guidelines at https://www.google.com/design/spec/components/bottom-navigation.html

Material Bottom Navigation Library Lightweight Bottom Navigation library component inspired by the Google Material Design Guidelines at https://www.go

Alessandro Crugnola 1.4k Dec 18, 2022
An Android Library that allows users to pull down a menu and select different actions. It can be implemented inside ScrollView, GridView, ListView.

AndroidPullMenu AndroidPullMenu is an Open Source Android library that allows developers to easily create applications with pull menu. The aim of this

Armando TBA 181 Nov 29, 2022
A dual-function menu button that offers a default action as well as the possibility of choosing a different action by selecting from a set of alternatives.

A dual-function menu button that offers a default action as well as the possibility of choosing a different action by selecting from a set of alternatives.

Kojo Fosu Bempa Edue 114 Nov 29, 2022
Neat library, that provides a simple way to implement guillotine-styled animation

Guillotine animation Neat library, that provides a simple way to implement guillotine-styled animation Check this [project on Dribbble] (https://dribb

Yalantis 2.7k Jan 3, 2023
swipe display drawer with flowing & bouncing effects.

FlowingDrawer swipe right to display drawer with flowing effects. Download Include the following dependency in your build.gradle file. Gradle: rep

mxn 2.6k Jan 3, 2023
Spotify like android material bottom navigation bar library.

SuperBottomBar About Spotify like android material bottom navigation bar library. GIF Design Credits All design and inspiration credits belongs to Spo

Ertugrul 73 Dec 10, 2022
Android Library for a DrawerLayout similar to the one in Google Apps

GoogleNavigationDrawerMenu This project aims to let you use a ListView menu similar to the one in the new Google Apps (Keep, Play Music...) without ha

Jorge Martin Espinosa 267 Nov 25, 2022
:fire: The powerful and easiest way to implement modern material popup menu.

PowerMenu ?? The powerful and easiest way to implement modern material popup menu. PowerMenu can be fully customized and used for popup dialogs. Downl

Jaewoong Eum 1k Dec 29, 2022
A new way to implement navigation in your app 🏎

ExpandableBottomBar A new way to improve navigation in your app Its really easy integrate to your project take it, faster, faster Important: library w

Alexander Dadukin 692 Dec 29, 2022
Simple and easy to use circular menu widget for Android.

Deprecated This project is no longer maintained. No new issues or pull requests will be accepted. You can still use the source or fork the project to

Anup Cowkur 420 Nov 25, 2022
Simple library which enable you to add a drawer(slide-out) navigation to your android application

SimpleSideDrawer is an android library to add a drawer navigation into your android application. This library has high affinity with other libraries l

null 217 Nov 25, 2022
A simple Floating Action Button that shows an anchored Navigation View

Floating Navigation View A simple Floating Action Button that shows an anchored Navigation View and was inspired by Menu Material Fixed created by Tom

André Mion 1.3k Dec 29, 2022
BottomSheet-Android - A simple customizable BottomSheet Library for Android Kotlin

BottomSheet-Android A simple customizable BottomSheet Library for Android Kotlin

Munachimso Ugorji 0 Jan 3, 2022