Skip to main content

Components

Snackbar

Snackbar displays informative text

banner-Snackbar

Usage

Snackbars notify users of processes that have been or will be performed by the app. They appear temporarily, towards the bottom of the screen. They must not interfere with the user experience, and they do not require user input to disappear.

usage snackbar

Basic Usage

Basic use of snackbars in fragments and in activities without customization


basic usage

Normal Snackbar

Using Extension Function*

...
with(binding) {
btnNormalTitleOnly.setOnClickListener {
normalSnackBar("Sample Text!")
}
}
...

Using Builder Pattern

...
with(binding) {
btnNormalTitleOnly.setOnClickListener {
//Fill setup parameter with fragment or activity
LgnSnackbar.setup(this) {
//Your Snackbar's customization here
title = message
}.show()
}


Success Snackbar

...
with(binding) {
btnNormalTitleOnly.setOnClickListener {
successSnackBar("Sample Text!")
}
}
...

Using Builder Pattern

...
with(binding) {
btnNormalTitleOnly.setOnClickListener {
//Fill setup parameter with fragment or activity
LgnSnackbar.setup(this) {
//Your Snackbar's customization here
title = message
type = LgnSnackbar.ToastType.SUCCESS
}.show()


Error Snackbar

...
with(binding) {
btnNormalTitleOnly.setOnClickListener {
errorSnackBar("Sample Text!")
}
}
...

Using Builder Pattern

...
with(binding) {
btnNormalTitleOnly.setOnClickListener {
//Fill setup parameter with fragment or activity
LgnSnackbar.setup(this) {
//Your Snackbar's customization here
title = message
type = LgnSnackbar.ToastType.ERROR
}.show()


Warning Snackbar

...
with(binding) {
btnNormalTitleOnly.setOnClickListener {
warningSnackBar("Sample Text!")
}
}
...

Using Builder Pattern

...
with(binding) {
btnNormalTitleOnly.setOnClickListener {
//Fill setup parameter with fragment or activity
LgnSnackbar.setup(this) {
//Your Snackbar's customization here
title = message
type = LgnSnackbar.ToastType.WARNING
}.show()


Advanced Usage

Further use of the snackbar in fragments and in activities with customization such as:

  • Title
  • Description
  • Action Button
  • Duration
  • etc
...
with(binding) {
btnNormalTitleImageButton.setOnClickListener {
//Fill setup parameter with fragment or activity
LgnSnackbar.setup(this) {
//Your Snackbar's customization here
title = "Sample Text!"
avatarUrl = "https://cdn.kincir.com/2/cojC8OAR0YiByhyEPOO6AADzHrc9p3w7CTursS4z35A/transform/rs:fit:764/src/production/2021-02/740x435_3576f9505b43dabaea0294436ab365775c42fe56.jpg"
actionText = "Button"

Attribute

Attribute NameXml AttrsRelated method(s)Description
Type SnackbarN/AtypeTo set Snackbar Type
View AnchorN/AviewTo set Snackbar Anchor View
Description TextN/AdescriptionTo set Snackbar Description
Title TextN/AtitleTo set Snackbar Title
Duration SnackbarN/AdurationTo set Snackbar Duration
Action TextN/AactionTextTo set Snackbar Action Text
Icon DrawableN/AiconTo set Snackbar Icon
Avatar UrlN/AavatarUrlTo set Snackbar Avatar Url
Callback ButtonN/AsetActionButtonListener { //Action }To set Snackbar Callback Action Button