✨ SweetAlertDialog with lottie! ✨
SweetAlert for Android, a beautiful and clever alert dialog with lottie animation effect!
Origin repo : https://github.com/pedant/sweet-alert-dialog
You can setup Lottie animation in 2parts.
NO | Explanation | Example |
---|---|---|
1. Lottie Icon in alert | loop no loop |
|
2. Full Screen Lottie | Lottie behind alert Lottie cover alert |
In your top-level build.gradle
file:
repositories {
...
mavenCentral()
}
In your app build.gradle
file:
dependencies {
implementation 'com.github.fascinate98:SweetLottieAlertDialog:[latest_version]'
}
Check here BASIC USAGE
-
Search Lottie animation you want.
-
Download lottie json file.
- (option) Change the downloaded file name.
- Make res -> New -> Android Resource Directory
- Make raw folder. (Resource type -> raw)
- Move json file downloaded to raw folder.
- In your Code
Make simple button for example.
In your xml file:
<Button
android:id="@+id/button1"
android:layout_margin="10dp"
android:text="Try me!" />
How to set lottie Icon in alert
In your Activity file:
//lottie icon in alert
button1.setOnClickListener {
//1. you have to set type SweetLottieAlertDialog.LOTTIE_ID_TYPE.
val lsd2 = SweetLottieAlertDialog(this, SweetLottieAlertDialog.LOTTIE_ID_TYPE)
//2. setLottieImagebyId(your_lottie_res, isLoop(boolean), listner)
lsd2.setLottieImagebyId(R.raw.lottie_cryingface, true, null)
lsd2.contentText = "Try Again!"
lsd2.show()
}
If you want set listner,
//lottie icon in alert
button1.setOnClickListener {
val lsd2 = SweetLottieAlertDialog(this, SweetLottieAlertDialog.LOTTIE_ID_TYPE)
//isLoop is false!
lsd2.setLottieImagebyId(R.raw.ok_btn_lottie, false, object : Animator.AnimatorListener {
override fun onAnimationStart(animation: Animator) {
}
override fun onAnimationEnd(animation: Animator) {
//this will be executed when lottie animation end.
lsd2.dismissWithAnimation()
}
override fun onAnimationCancel(animation: Animator) {
}
override fun onAnimationRepeat(animation: Animator) {
}
})
lsd2.contentText = "Success!"
lsd2.setCancelable(true)
lsd2.setCanceledOnTouchOutside(true)
lsd2.show()
}
How to set Full screen lottie
//full screen - Lottie cover alert
button1.setOnClickListener {
val lsd = SweetLottieAlertDialog(this, SweetLottieAlertDialog.NORMAL_TYPE)
//text in alert
lsd.contentText = "Congratulation!"
//set full screen lottie. It will cover your alert.
//setPopupLottieAnimation(your_lottie_res, isLoop(boolean), elevation);
lsd.setPopupLottieAnimation(R.raw.bg_lottie, false, 999f)
lsd.show()
}
if you want lottie behind alert,
//full screen - Lottie behind alert
button1.setOnClickListener {
val lsd = SweetLottieAlertDialog(this, SweetLottieAlertDialog.NORMAL_TYPE)
//text in alert
lsd.contentText = "Congratulation!"
//set full screen lottie behind alert.
//set elevation 0f. v here!
lsd.setPopupLottieAnimation(R.raw.bg_lottie, false, 0f)
lsd.show()
}
The MIT License (MIT)
Copyright (c) 2014 Pedant(http://pedant.cn)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.