Home

Awesome

BottomSheetMenu

Android Arsenal

<img src="https://github.com/Kennyc1012/BottomSheetMenu/blob/master/art/ss3.png" width="480"/> <img src="https://github.com/Kennyc1012/BottomSheetMenu/blob/master/art/ss2.png" width="480"/> <img src="https://github.com/Kennyc1012/BottomSheetMenu/blob/master/art/ss1.png" width="480"/>

Features

Using BottomSheetMenu

To get started using BottomSheetMenu, first you'll need to create a menu resource file with the defined actions.

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">

    <item
        android:id="@+id/share"
        android:icon="@drawable/ic_share_grey_600_24dp"
        android:title="Share" />

    <item
        android:id="@+id/upload"
        android:icon="@drawable/ic_cloud_upload_grey_600_24dp"
        android:title="Upload" />

    <item
        android:id="@+id/copy"
        android:icon="@drawable/ic_content_copy_grey_600_24dp"
        android:title="Copy" />

    <item
        android:id="@+id/print"
        android:icon="@drawable/ic_print_grey_600_24dp"
        android:title="Print" />

</menu>

Then create a BottomSheetMenuDialogFragment via the Builder class using either the Builder method calls for java or named arguments for Kotlin

new BottomSheetMenuDialogFragment.Builder(getActivity())
  .setSheet(R.menu.bottom_sheet)
  .setTitle(R.string.options)
  .setListener(myListener)
  .setObject(myObject)
  .show(getSupportFragmentManager());
BottomSheetMenuDialogFragment.Builder(context = this,
      sheet = R.menu.bottom_sheet,
      listener = myListener,
      title = R.string.options,
      `object` = myObject)
      .show(supportFragmentManager)

Styling

BottomSheetMenu comes with both a Light and Dark theme to accommodate most scenarios. However, if you want to customize itr more, you can create your own style and supply it to the builder. </br> Customizable attributes are:

<!-- The text appearance of the title -->
<attr name="bottom_sheet_menu_title_text_appearance" format="reference" />

<!-- The number of columns to show when using the grid style -->
<attr name="bottom_sheet_menu_column_count" format="integer" />

<!-- The text appearance of the list items -->
<attr name="bottom_sheet_menu_list_text_appearance" format="reference" />

<!-- The text appearance of the grid items -->
<attr name="bottom_sheet_menu_grid_text_appearance" format="reference" />

<!-- The text appearance of the close title -->
<attr name="bottom_sheet_menu_close_title_text_appearance" format="reference" />

<!-- The icon used for the close button -->
<attr name="bottom_sheet_menu_close_button_icon" format="reference" />

Then create a style

<style name="MyBottomSheetMenuStyle" parent="@style/Theme.BottomSheetMenuDialog">
    <item name="bottom_sheet_menu_title_text_appearance">@style/TitleAppearance</item>
    <item name="bottom_sheet_menu_list_text_appearance">@style/ListAppearance</item>
    <item name="bottom_sheet_menu_grid_text_appearance">@style/GridAppearance</item>
</style>

<style name="TitleAppearance" parent="TextAppearance.Material3.TitleLarge">
    <item name="android:textColor">@android:color/holo_green_light</item>
</style>

<style name="ListAppearance" parent="TextAppearance.Material3.BodyMedium">
    <item name="android:textColor">@android:color/holo_red_light</item>
    <item name="android:textSize">18sp</item>
</style>

<style name="GridAppearance" parent="TextAppearance.Material3.BodyMedium">
    <item name="android:textColor">@android:color/holo_red_light</item>
    <item name="android:textSize">20sp</item>
</style>

Also note that each of these pre-defined styles also have a light and DayNight theme. They are named similary with a .Light or DayNight added to the end of the style name</br> @style/Theme.BottomSheetMenuDialog.Light @style/BottomSheetMenu.Title.TextAppearance.Light etc...

Then finally pass the style into the Builder object.

new BottomSheetMenuDialogFragment.Builder(getActivity(), R.style.MyBottomSheetStyle)
  .setSheet(R.menu.bottom_sheet)
  .setTitle(R.string.options)
  .setListener(myListener)
  .show();
BottomSheetMenuDialogFragment.Builder(context = this,
        sheet = R.menu.bottom_sheet,
        title = R.string.options,
        listener = myListener,
        style = R.style.MyBottomSheetStyle)
        .show(supportFragmentManager)

Callbacks

BottomSheetMenu uses the BottomSheetListener for callbacks

 /**
     * Called when the [BottomSheetMenuDialogFragment] is first displayed
     *
     * @param bottomSheet The [BottomSheetMenuDialogFragment] that was shown
     * @param object      Optional [Object] to pass to the [BottomSheetMenuDialogFragment]
     */
    fun onSheetShown(bottomSheet: BottomSheetMenuDialogFragment, `object`: Any?)

    /**
     * Called when an item is selected from the list/grid of the [BottomSheetMenuDialogFragment]
     *
     * @param bottomSheet The [BottomSheetMenuDialogFragment] that had an item selected
     * @param item        The item that was selected
     * @param object      Optional [Object] to pass to the [BottomSheetMenuDialogFragment]
     */
    fun onSheetItemSelected(bottomSheet: BottomSheetMenuDialogFragment, item: MenuItem, `object`: Any?)

    /**
     * Called when the [BottomSheetMenuDialogFragment] has been dismissed
     *
     * @param bottomSheet  The [BottomSheetMenuDialogFragment] that was dismissed
     * @param object       Optional [Object] to pass to the [BottomSheetMenuDialogFragment]
     * @param dismissEvent How the [BottomSheetMenuDialogFragment] was dismissed. Possible values are: <br></br>
     *  * [.DISMISS_EVENT_SWIPE]
     *  * [.DISMISS_EVENT_MANUAL]
     *  * [.DISMISS_EVENT_ITEM_SELECTED]
     */
    fun onSheetDismissed(bottomSheet: BottomSheetMenuDialogFragment, `object`: Any?, @DismissEvent dismissEvent: Int)

Upgrading to 5.X

Upgrading to 4.X

Upgrading to 3.X

Upgrading From 1.x

When upgrading to 2.x from a 1.x release, some changes will have to be made.

Including in your project

To include BottomSheet in your project, make the following changes to your build.gradle file

Add repository

allprojects {
    repositories {
        ...
        maven { url "https://jitpack.io" }
    }
}

Add dependency

dependencies {
     implementation "com.github.Kennyc1012:BottomSheetMenu:5.1.1"

Contribution

Pull requests are welcomed and encouraged. If you experience any bugs, please file an issue

License

Copyright 2015 Kenny Campagna

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.