Android library that provides an animated customizable snack bar.
- View on demand a custom snack bar from the top of the screen.
- Pass custom message to show in the snack bar.
- The snack bar disappears automatically after a few seconds.
- Dismiss the bar programmatically on demand.
- Customize various features like background, font, icon and tint.
- Use your own custom view in the snack bar.
- Automatically detect and start animated drawables in background.
These are GIFs and may take a few seconds to load if you have a slow connection.
- You can customize multiple features in the snackbar:
- Background color or drawable.
- Text message color.
- Icon drawable and tint.
- Text Font.
- Auto hide duration.
- Automatic status bar padding handling
- Add your own custom view.
- Click behaviour. (Planned)
- Add more customization features.
- Enhance the readme.md file with images and examples.
- Step 1. Add the JitPack repository to your build file Add it in your root build.gradle at the end of repositories:
allprojects {
repositories {
//...
maven { url 'https://jitpack.io' }
}
}
- Step 2. Add the dependency to your app build.gradle
dependencies {
implementation 'com.github.AmrSaleh:AnimatedSnackbar:v2.0' // Make sure to replace with latest version tag
}
AnimatedSnackbar(context)
.setMessage(getString(R.string.dummy_message))
.show()
The snack bar will auto hide after a few seconds but you can also manually hide the snack bar by calling the "hide" function.
//val spannableString = SpannableString("This is a spannable string")
// spannableString.setSpan(ForegroundColorSpan(Color.RED), 0, 4, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE)
AnimatedSnackbar(context)
.setMessage(spannableString)
.show()
// val animationDrawable = getDrawable(R.drawable.drawable_gradient_animation_list) as AnimationDrawable
AnimatedSnackbar(context)
.setMessage(getString(R.string.dummy_message), ContextCompat.getColor(this@MainActivity, android.R.color.white))
.setTextSize(15f)
.setTypeFace(Typeface.DEFAULT_BOLD)
.setIconDrawable(getDrawable(android.R.drawable.ic_dialog_email), ContextCompat.getColor(this@MainActivity, R.color.greenLight))
.setBgDrawable(animationDrawable)
.setAnimationDurationMillis(600)
.setAutoHide(true, 4000)
.setAddStatusBarPadding(true) // default true
.show()
Second parameter in any setter is optional and you can always enter only first parameter if you like.
AnimatedSnackbar(context)
.setCustomView(R.layout.my_custom_view)
.show()
Just make sure to use
- id
icon_image_view
for your image view. - id
message_text_view
for your text view.
// Customizations can be set before or after setting your custom view (How cool is that!)
AnimatedSnackbar(context)
.setMessage("Yay! I set this message before or after setting my custom view")
.setCustomView(R.layout.my_custom_view)
.setBgDrawable(ColorDrawable(ContextCompat.getColor(this, R.color.darkGray)))
.setIconDrawable(getDrawable(android.R.drawable.ic_dialog_email))
.show()
// val snackbar = AnimatedSnackbar(context).setMessage(getString(R.string.dummy_message))
// snackbar.show()
snackbar.hide()
More description is planned to be added here, but for now please refer to the included example project for further clarification.
Licensed under the Apache License, Version 2.0