Skip to content

2 Specifying a title and icon

Michael Rapp edited this page Dec 30, 2017 · 1 revision

In order to create a bottom sheet, an instance of the class BottomSheet.Builder has to be created at first. The builder therefore provides the constructor Builder(Context), which expects an instance of the class Context as a parameter.

To specify the title of the bottom sheet, which should be created by the builder, the following two methods can be used. One of them allows to pass the title as an instance of the type CharSequence, the other one expects the resource id of a string resource as a parameter.

setTitle(CharSequence):Builder
setTitle(int):Builder

To show an icon to the left of the bottom sheet's title, the following three methods can be used. The icon is also shown if no title is specified.

setIcon(Drawable):Builder
setIcon(int):Builder
setIconAttribute(int):Builder

The setIcon-methods shown above allow to specify the icon by either passing an instance of the class Drawable or the resource id of a drawable resource as a parameter. The setIconAttribute-method allows to pass an attribute of the theme, which is used by the bottom sheet, and which specifies a drawable. An example of such an attribute is android.R.attr.alertDialogIcon.