Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/TonnyL/Light
🍭 The usual Snackbar, but elegant
https://github.com/TonnyL/Light
android kotlin kotlin-android kotlin-library material-components material-design snackbar ui-components
Last synced: about 2 months ago
JSON representation
🍭 The usual Snackbar, but elegant
- Host: GitHub
- URL: https://github.com/TonnyL/Light
- Owner: TonnyL
- License: mit
- Created: 2017-05-05T15:47:01.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-07-14T03:15:23.000Z (over 6 years ago)
- Last Synced: 2024-08-01T01:30:51.574Z (4 months ago)
- Topics: android, kotlin, kotlin-android, kotlin-library, material-components, material-design, snackbar, ui-components
- Language: Kotlin
- Homepage:
- Size: 460 KB
- Stars: 547
- Watchers: 12
- Forks: 34
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-kotlin - Light - 🍭 The usual Snackbar, but elegant (Libraries)
- awesome-kotlin-android - Light - 优雅通用的 Snackbar🔥🔥🔥 (开源库 / UI)
- awesome-list - TonnyL/Light - 🍭 The usual Snackbar, but elegant (Kotlin)
- awesome-github-android-ui - Light - 更好的Snackbar实现 (Snackbar)
README
# Light
[![Build Status](https://travis-ci.org/TonnyL/Light.svg?branch=master)](https://travis-ci.org/TonnyL/Light)
[ ![Download](https://api.bintray.com/packages/tonnyl/maven/light/images/download.svg) ](https://bintray.com/tonnyl/maven/light/_latestVersion)
The usual Snackbar, but elegant. Inspired by [Toasty](https://github.com/GrenderG/Toasty).
## Screenshots
| success | Info | warning |
| :-------------: | :-------------: | :-------------: |
| ![Success](./images/success.png) | ![Info](./images/info.png) | ![Warning](./images/warning.png) || Error | Normal | Custom |
| :-------------: | :-------------: | :-------------: |
| ![Error](./images/error.png) | ![Normal](./images/normal.png) | ![Custom](./images/custom.png) |## Download
### Gradle
Add the code below to your **root** `build.gradle` file (`NOT` your module `build.gradle` file, check [here](./build.gradle) for an example).
```gradle
allprojects {
repositories {
jcenter()
}
}
```Add the code below to your **module**'s `build.gradle` file:
```gradle
dependencies {
implementation 'io.github.tonnyl:light:latest_version'
}
```### Maven
```xml
io.github.tonnyl
light
latest_version
pom```
## Usage
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
// Kotlin
import io.github.tonnyl.light.successsuccess(fab, "Success", Snackbar.LENGTH_SHORT)
.setAction("Action", {
Toast.makeText(this@MainActivity, "Hello, Light!", Toast.LENGTH_SHORT).show()
})
.show()
``````Java
// Java
Light.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
// Kotlin
import io.github.tonnyl.light.infoinfo(fab, "Info", Snackbar.LENGTH_SHORT).show()
``````Java
// Java
Light.info(fab, "Info", Snackbar.LENGTH_SHORT).show());
```+ To display a warning Snackbar:
```Kotlin
// Kotlin
import io.github.tonnyl.light.warningwarning(fab, "Warning", Snackbar.LENGTH_SHORT).show()
``````Java
// Java
Light.warning(fab, "Warning", Snackbar.LENGTH_SHORT).show());
```+ To display an error Snackbar:
```Kotlin
// Kotlin
import io.github.tonnyl.light.errorerror(fab, "Error", Snackbar.LENGTH_SHORT).show()
``````Java
// Java
Light.error(fab, "Error", Snackbar.LENGTH_SHORT).show());
```+ To display the usual Snackbar:
```Kotlin
// Kotlin
import io.github.tonnyl.light.normalnormal(fab, "Normal", Snackbar.LENGTH_SHORT).show()
``````Java
// Java
Light.normal(fab, "Normal", Snackbar.LENGTH_SHORT).show();
```+ You can also create your own Snackbar in custom-designed style:
```Kotlin
// Kotlin
import io.github.tonnyl.light.makemake(
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
// Java
Light.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());
```## Extra
[You can pass formatted text to Light!](./app/src/main/java/io/github/tonnyl/sample/MainActivity.kt#L70-L79)
## Pull Request
Have some new ideas or find a bug? Do not hesitate to open an `issue` and make a `pull request`.
## License
**Light** is under an **MIT** license. See the [LICENSE](LICENSE) file for more info.