BottomSheetBuilder - 一個簡單的庫能夠根據Material Design規范創建BottomSheets

jopen 8年前發布 | 53K 次閱讀 Android開發 移動開發 BottomSheetBuilder

BottomSheetBuilder

BottomSheetBuilder - 一個簡單的庫能夠根據Material Design規范創建BottomSheets

Available from API 14.

  • Add the following to your build.gradle:

    repositories{
      maven { url "https://jitpack.io" }
    }
    
    dependencies {
      compile 'com.github.rubensousa:BottomSheetBuilder:0.2.1'
    }
  • Create a view (the builder already inflates the view inside the coordinatorLayout):

    View bottomSheet = new BottomSheetBuilder(context, coordinatorLayout)
            .setMode(BottomSheetBuilder.MODE_GRID)
            .setBackgroundColor(android.R.color.white)
            .setMenu(R.menu.menu_bottom_grid_sheet)
            .setItemClickListener(this)
            .createView();
  • Create a BottomSheetDialog:

    BottomSheetDialog dialog = new BottomSheetBuilder(context, R.style.AppTheme_BottomSheetDialog)
                  .setMode(BottomSheetBuilder.MODE_LIST)
                  .setBackgroundColor(android.R.color.white)
                  .setMenu(R.menu.menu_bottom_simple_sheet)
                  .setItemClickListener(new BottomSheetItemClickListener() {
                            @Override
                            public void onBottomSheetItemClick(BottomSheetMenuItem item) {
                                    mBottomSheetDialog.dismiss();
                            }
                    })
                  .createDialog();
    
    dialog.show();

Styling

Make sure the style passed in the BottomSheetBuilder's constructor extends from Theme.Design.BottomSheetDialog:

<style name="AppTheme.BottomSheetDialog" parent="Theme.Design.BottomSheetDialog">
    <!-- This changes the overlay background -->
    <item name="android:background">@color/colorAccent</item>
</style>

示例

The sample includes 3 view modes: grid, list and list with one submenu. Check the screenshots below.

Customization methods

setItemTextColor(@ColorRes int color)
setTitleTextColor(@ColorRes int color)
setBackground(@DrawableRes int background)
setBackgroundColor(@ColorRes int background)
setDividerBackground(@DrawableRes int background)
setItemBackground(@DrawableRes int background)

Known bugs

There's some bugs that affect the BottomSheetDialog and the BottomSheetBehavior in the Support Library v23.2.0:

Screenshots

  
項目地址: https://github.com/rubensousa/BottomSheetBuilder

 本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!