This repository was archived by the owner on Aug 21, 2021. It is now read-only.
- Notifications
You must be signed in to change notification settings - Fork 47
Usage
Michael Bely edited this page Oct 7, 2018 · 40 revisions
import org.michaelbel.bottomsheet.BottomSheet; import org.michaelbel.bottomsheet.BottomSheetCallback; import org.michaelbel.bottomsheet.Utils;BottomSheet.Builder builder = new BottomSheet.Builder(context);CharSequence, String or StringRes types.
builder.setTitle("My title"); builder.setTitle(R.string.title_text);Title textView getter:
builder.getTitleTextView().setText("My text"); builder.getTitleTextView().setTextSize(14);Firstly, set the items: (CharSequence, String, StringRes, ArrayRes types) like this:
String[] items = new String[] { "Share", "Upload", "Copy", "Print this page" };CharSequence[] items = new CharSequence[] { "Share", "Upload", "Copy", "Print this page" };int[] items = new int[] { R.string.share, R.string.upload, R.string.copy, R.string.print_this_page };XML string array:
<string-array name="strings"> <item>Share</item> <item>Upload</item> <item>Copy</item> <item>Print</item> </string-array>Secondly, if you want to use the icons (Drawable, Int types):
int[] icons = new int[] { R.drawable.ic_share, R.drawable.ic_upload, R.drawable.ic_copy, R.drawable.ic_print };Drawable[] icons = new Drawable[] { ContextCompat.getDrawable(context, R.drawable.ic_share), ContextCompat.getDrawable(context, R.drawable.ic_upload), ContextCompat.getDrawable(context, R.drawable.ic_copy), ContextCompat.getDrawable(context, R.drawable.ic_print) };And call the method:
builder.setItems(items, icons, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // your code here. } });- Create a menu layout file:
<menu xmlns:android="http://schemas.android.com/apk/res/android"> <item android:title="@string/share" android:icon="@drawable/ic_share"/> <item android:title="@string/upload" android:icon="@drawable/ic_upload"/> <item android:title="@string/copy" android:icon="@drawable/ic_copy"/> <item android:title="@string/print_this_page" android:icon="@drawable/ic_print"/> </menu>- Call the method:
builder.setMenu(R.menu.menu_items, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // your code here. } });BottomSheet.LIST or BottomSheet.GRID types. List by default.
builder.setContentType(BottomSheet.LIST); builder.setContentType(BottomSheet.GRID);builder.setTitleTextColor(Color.RED); builder.setTitleTextColor(0xFFFF5252); builder.setTitleTextColor(getResources().getColor(R.color.my_color)); builder.setTitleTextColor(ContextCompat.getColor(context, R.color.my_color));Direct call:
builder.setTitleTextColorRes(R.color.my_color);builder.setItemTextColor(Color.RED); builder.setItemTextColor(0xFFFF5252); builder.setItemTextColor(getResources().getColor(R.color.my_color)); builder.setItemTextColor(ContextCompat.getColor(context, R.color.my_color));Direct call:
builder.setItemTextColorRes(R.color.my_color);builder.setBackgroundColor(Color.RED); builder.setBackgroundColor(0xFFFF5252); builder.setBackgroundColor(getResources().getColor(R.color.my_color)); builder.setBackgroundColor(ContextCompat.getColor(context, R.color.my_color));Direct call:
builder.setBackgroundColorRes(R.color.my_color);builder.setIconColor(Color.RED); builder.setIconColor(0xFFFF5252); builder.setIconColor(getResources().getColor(R.color.my_color)); builder.setIconColor(ContextCompat.getColor(context, R.color.my_color));Direct call:
builder.setIconColorRes(R.color.my_color);Boolean, BoolRes types.
builder.setFullWidth(true); builder.setFullWidth(R.bool.full_width);| Full width | Default |
|---|---|
![]() | ![]() |
Int type. 48dp default.
builder.setCellHeight(Utils.dp(this, 52);Boolean, BoolRes types.
builder.setDividers(true); builder.setDividers(R.bool.dividers);| Light | Dark |
|---|---|
![]() | ![]() |
Boolean, BoolRes types.
builder.setTitleMultiline(true); builder.setTitleMultiline(R.bool.multiline);Boolean, BoolRes types.
builder.setDarkTheme(true); builder.setDarkTheme(R.bool.multiline);Int type. Range from 0 to 255.
builder.setWindowDimming(100);BottomSheet.FAB_SLIDE_UP or BottomSheet.FAB_SHOW_HIDE types.
builder.setFabBehavior(floatingActionButton, BottomSheet.FAB_SHOW_HIDE);builder.setOnShowListener(new DialogInterface.OnShowListener() { @Override public void onShow(DialogInterface dialog) { // your code here. } });builder.setOnDismissListener(new DialogInterface.OnDismissListener() { @Override public void onDismiss(DialogInterface dialog) { // your code here. } });builder.setCallback(new BottomSheetCallback() { @Override public void onShown() { // your code here. } @Override public void onDismissed() { // and here. } });builder.show();


