diff --git a/README.md b/README.md index 732d099..c8866ea 100644 --- a/README.md +++ b/README.md @@ -65,6 +65,20 @@ BottomSheetMenuDialog dialog = new BottomSheetBuilder(context, R.style.AppTheme_ .setIconTintColorResource(R.color.colorPrimary) ... ``` +- If you want to add the menu items programmetically. If you are using this method you can also add menu file without any item. +```java +BottomSheetMenuDialog dialog = new BottomSheetBuilder(context, R.style.AppTheme_BottomSheetDialog) + .addItem(Menu.NONE,1,4,"Item Name", R.drawable.drawable_name) + .addItem(Menu.NONE,2,4,"Item Name1", anyDrawable) + .addItem(Menu.NONE,3,4,"Item Name2", anyBitmap) + ... + +// full function definition +// public BottomSheetBuilder addItem(int groupId,int itemId,int order, CharSequence title,int iconDrawableResource) + + +``` + ## Styling Make sure the style passed in the BottomSheetBuilder's constructor extends from the Theme.Design.BottomSheetDialog family: diff --git a/bottomsheetbuilder/src/main/java/com/github/rubensousa/bottomsheetbuilder/BottomSheetBuilder.java b/bottomsheetbuilder/src/main/java/com/github/rubensousa/bottomsheetbuilder/BottomSheetBuilder.java index 23c3a38..4d3d0df 100644 --- a/bottomsheetbuilder/src/main/java/com/github/rubensousa/bottomsheetbuilder/BottomSheetBuilder.java +++ b/bottomsheetbuilder/src/main/java/com/github/rubensousa/bottomsheetbuilder/BottomSheetBuilder.java @@ -18,6 +18,9 @@ import android.content.Context; import android.content.res.TypedArray; +import android.graphics.Bitmap; +import android.graphics.drawable.BitmapDrawable; +import android.graphics.drawable.Drawable; import android.os.Build; import android.support.annotation.ColorInt; import android.support.annotation.ColorRes; @@ -34,6 +37,7 @@ import android.support.v7.view.menu.MenuBuilder; import android.view.Gravity; import android.view.Menu; +import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; import android.widget.FrameLayout; @@ -90,7 +94,6 @@ public BottomSheetBuilder(Context context, @StyleRes int theme) { } public BottomSheetBuilder setMode(int mode) { - if (mode != MODE_LIST && mode != MODE_GRID) { throw new IllegalArgumentException("Mode must be one of BottomSheetBuilder.MODE_LIST" + "or BottomSheetBuilder.MODE_GRID"); @@ -117,6 +120,55 @@ public BottomSheetBuilder setMenu(Menu menu) { return this; } + /** + * Add a new item to the menu. This item displays the given title for its label. + * + * @param groupId The group identifier that this item should be part of. This can be used to define groups of items for batch state changes. Normally use Menu.NONE if an item should not be in a group. + * @param itemId Unique item ID. Use Menu.NONE if you do not need a unique ID. + * @param order The order for the item. Use Menu.NONE if you do not care about the order. + * @param title The text to display for the item. + * @param iconDrawable The icon of the menu item. Use null if don't want to use icon. + */ + + public BottomSheetBuilder addItem(int groupId,int itemId,int order, CharSequence title,Drawable iconDrawable){ + MenuItem newItem=mMenu.add(groupId,itemId,order,title); + newItem.setIcon(iconDrawable); + return this; + } + + /** + * Add a new item to the menu. This item displays the given title for its label. + * + * @param groupId The group identifier that this item should be part of. This can be used to define groups of items for batch state changes. Normally use Menu.NONE if an item should not be in a group. + * @param itemId Unique item ID. Use Menu.NONE if you do not need a unique ID. + * @param order The order for the item. Use Menu.NONE if you do not care about the order. + * @param title The text to display for the item. + * @param iconBitmap The icon of the menu item. Use null if don't want to use icon. + */ + + public BottomSheetBuilder addItem(int groupId,int itemId,int order, CharSequence title,Bitmap iconBitmap){ + MenuItem newItem=mMenu.add(groupId,itemId,order,title); + newItem.setIcon(new BitmapDrawable(mContext.getResources(), iconBitmap)); + return this; + } + + + /** + * Add a new item to the menu. This item displays the given title for its label. + * + * @param groupId The group identifier that this item should be part of. This can be used to define groups of items for batch state changes. Normally use NONE if an item should not be in a group. + * @param itemId Unique item ID. Use Menu.NONE if you do not need a unique ID. + * @param order The order for the item. Use Menu.NONE if you do not care about the order. + * @param title The text to display for the item. + * @param iconDrawableResource The icon of the menu item. Use 0 if don't want to use icon. + */ + + public BottomSheetBuilder addItem(int groupId,int itemId,int order, CharSequence title,int iconDrawableResource){ + MenuItem newItem=mMenu.add(groupId,itemId,order,title); + newItem.setIcon(iconDrawableResource); + return this; + } + public BottomSheetBuilder setItemTextColor(@ColorInt int color) { mItemTextColor = color; return this;