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

02. Snackbar Message #2

Merged
merged 3 commits into from
May 4, 2020
Merged

02. Snackbar Message #2

merged 3 commits into from
May 4, 2020

Conversation

AnelCC
Copy link
Owner

@AnelCC AnelCC commented May 4, 2020

02 Snackbar Message

You can use a Snackbar to display a brief message to the user. The message automatically goes away after a short period. A Snackbar is ideal for brief messages that the user doesn't necessarily need to act on. For example, an email app could use a Snackbar to tell the user that the app successfully sent an email.

  • Displays a short, momentary text message
  • Displays a quick messages to acknowledges something
  • Can be displayed fro a short or longer amount of time.
  • Appear of the bottom of the screen
  • Have the ability to specify a clickleable action.

Available duration presets are: LENGTH_INDEFINITE, LENGTH_LONG, LENGTH_SHORT

2. Created a simple Snackbar: LENGTH_LONG

Simple Snackbar

 private fun showSnackbar() {
        Snackbar.make(findViewById(R.id.snackbar_coordinator_layout), "This is a snackbar LENGTH_LONG", Snackbar.LENGTH_LONG).show()
}

snackbar_page snackbar_simple

3. Created a custom Snackbar: LENGTH_LONG

Custom Snackbar

private fun showActionSnackbar() {
        val snackbar = Snackbar.make(findViewById(R.id.snackbar_coordinator_layout), "This is a snackbar", Snackbar.LENGTH_LONG)

        snackbar.setBackgroundTint(getColor(R.color.colorAccent))
        snackbar.setAction("Click here!") {
            Toast.makeText(applicationContext, "Snackbar Action Click!", Toast.LENGTH_SHORT).show()
        }
        snackbar.setActionTextColor(getColor(R.color.colorPrimaryDark))
        snackbar.show()
}

snackbar_custom snackbar_custom_w_action

More info here!

@AnelCC AnelCC merged commit 161a8f6 into master May 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant