Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add items programmetically feature #13

Merged
merged 1 commit into from
Feb 7, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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");
Expand All @@ -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;
Expand Down