The usual Snackbar, but elegant. Inspired by Toasty.
success | Info | warning |
---|---|---|
Error | Normal | Custom |
---|---|---|
Add the code below to your root build.gradle
file (NOT
your module build.gradle
file, check here for an example).
allprojects {
repositories {
jcenter()
}
}
Add the code below to your module's build.gradle
file:
dependencies {
// Other dependencies here.
implementation 'io.github.tonnyl:light:1.1.0'
}
<dependency>
<groupId>io.github.tonnyl</groupId>
<artifactId>light</artifactId>
<version>1.1.0</version>
<type>pom</type>
</dependency>
Each method always returns a Snackbar
object, so you can customize the Snackbar much more. DO NOT FORGET TO CALL THE show()
METHOD!
- To display a success Snackbar:
// Kotlin
Light.success(fab, "Success", Snackbar.LENGTH_SHORT)
.setAction("Action", {
Toast.makeText(this@MainActivity, "Hello, Light!", Toast.LENGTH_SHORT).show()
})
.show()
// Java
Light.Companion.success(fab, "Success", Snackbar.LENGTH_SHORT)
.setAction("Action", v ->
Toast.makeText(SettingsActivity.this, "Hello, Light!", Toast.LENGTH_SHORT).show())
.show());
- To display an info Snackbar:
// Kotlin
Light.info(fab, "Info", Snackbar.LENGTH_SHORT).show()
// Java
Light.Companion.info(fab, "Info", Snackbar.LENGTH_SHORT).show());
- To display a warning Snackbar:
// Kotlin
Light.warning(fab, "Warning", Snackbar.LENGTH_SHORT).show()
// Java
Light.Companion.warning(fab, "Warning", Snackbar.LENGTH_SHORT).show());
- To display an error Snackbar:
// Kotlin
Light.error(fab, "Error", Snackbar.LENGTH_SHORT).show()
// Java
Light.Companion.error(fab, "Error", Snackbar.LENGTH_SHORT).show());
- To display the usual Snackbar:
// Kotlin
Light.normal(fab, "Normal", Snackbar.LENGTH_SHORT).show()
Light.Companion.normal(fab, "Normal", Snackbar.LENGTH_SHORT).show();
- You can also create your own Snackbar in custom-designed style:
// Kotlin
Light.make(
fab, // // The view to find a parent from.
"Awesome Snackbar", // The message to show.
Snackbar.LENGTH_INDEFINITE, // How long to display the message.
R.drawable.ic_album_white_24dp, // The left icon of message to show.
R.color.color_cyan, // The background color of Snackbar.
android.R.color.white, // The color of text to show.
R.drawable.ic_done_all_white_24dp,
R.color.colorAccent) // The left icon of action text.
.setAction("Done all", {
// Do whatever you want to do.
Toast.makeText(this@MainActivity, "Hello, Light!", Toast.LENGTH_SHORT).show()
})
.show()
// Java
Light.Companion.make(
fab,
"Awesome Snackbar",
Snackbar.LENGTH_SHORT,
R.drawable.ic_album_white_24dp,
R.color.color_cyan,
android.R.color.white,
R.drawable.ic_done_all_white_24dp,
R.color.colorAccent)
.setAction("Done all", v ->
Toast.makeText(SettingsActivity.this, "Hello, Light!", Toast.LENGTH_SHORT).show())
.show());
You can pass formatted text to Light!
Have some new ideas or find a bug? Do not hesitate to open an issue
and make a pull request
.
Light is under an MIT license. See the LICENSE file for more info.