Skip to content
This repository was archived by the owner on Aug 21, 2021. It is now read-only.
Michael Bel edited this page Mar 9, 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);

Set Title

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);

Set Items

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.
    }
});

Set Menu

  1. 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>
  1. Call the method:
builder.setMenu(R.menu.menu_items, new DialogInterface.OnClickListener() {
    @Override
    public void onClick(DialogInterface dialog, int which) {
        // your code here.
    }
});

Set Content type

BottomSheet.LIST or BottomSheet.GRID types. List by default.

builder.setContentType(BottomSheet.LIST);
builder.setContentType(BottomSheet.GRID);

Set Title text color

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);

Set Items text 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);

Set Background 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);

Set Icons 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);

Set Full width

Boolean, BoolRes types.

builder.setFullWidth(true);
builder.setFullWidth(R.bool.full_width);
Full width Default

Set Cell height

Int type. 48dp default.

builder.setCellHeight(Utils.dp(this, 52);

Set Dividers

Boolean, BoolRes types.

builder.setDividers(true);
builder.setDividers(R.bool.dividers);
Light Dark

Set Title multiline

Boolean, BoolRes types.

builder.setTitleMultiline(true);
builder.setTitleMultiline(R.bool.multiline);

Set Dark theme.

Boolean, BoolRes types.

builder.setDarkTheme(true);
builder.setDarkTheme(R.bool.multiline);

Set Window dimming

Int type. Range from 0 to 255.

builder.setWindowDimming(100);

Set Show listener

builder.setOnShowListener(new DialogInterface.OnShowListener() {
    @Override
    public void onShow(DialogInterface dialog) {
        // your code here.
    }
});

Set Dismiss listener

builder.setOnDismissListener(new DialogInterface.OnDismissListener() {
    @Override
    public void onDismiss(DialogInterface dialog) {
        // your code here.
    }
});

Set Callback

builder.setCallback(new BottomSheetCallback() {
    @Override
    public void onShown() {
        // your code here.
    }

    @Override
    public void onDismissed() {
        // and here.
    }
});

Set View

Coming soon.

Getter:

builder.getView();

Set Items selector

Coming soon.


Set Theme

Coming soon.


Set Dismiss with swipe

Coming soon.


Set Divider color

Coming soon


Set SingleChoice items

Coming soon


Set MultiChoice items

Coming soon


Show dialog

builder.show();

@Deprecated

setCustomView(...) - Use setView instead.

Clone this wiki locally