preface
Different Android systems have different Toast UI, and it is very simple. Before, I just encapsulated a tool class to use. After seeing Lottie, I wanted to make a nice Toast, so I took the time to write a nice Toast.
ToastBox is a custom toast library, which can implement a variety of custom toast. There are WindowsManger and system toast implementations. With Lottie animation library, you can make some beautiful toast
There are plenty of tools on Github for Toast, but I just love building wheels lol
Example:
ToastBox allows you to customize your View, display duration, display location, and all kinds of custom styles. I’ve written down some of the most common toastboxes, such as network error, operation success, message, and failure.
Some interesting toast:
Success:
fail:
Network error:
General information:
Ordinary toast:
For a demo of LottieToast, see LottieActivity
Lottie has lots of great animations, and you can design your own.
Lottie Animation Lottie development documentation
Implementation:
Concrete implementation can see the code, here will not be detailed
-
There are two toast implementations, one is the system TOAST, the other is the Windows implementation, both good and bad, when the call can be flexible configuration
-
Need to be initialized in the Application, use ActivityLifecycleCallbacks used to monitor the activity life cycle, to avoid memory leaks.
Fast access:
Add it in your root build.gradle at the end of repositories:
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
Copy the code
Step 2. Add the dependency
dependencies {
implementation 'com.github.xluu233:ToastBox:${version}'
}
Copy the code
Use:
Stetup1: Initialized in Application
ToastBoxRegister.init(this)
Copy the code
You can configure some parameters during initialization
Toastboxregister.init (this).apply {//text style: White and grey textStyle = textstyle.white // You can set the default display icon defaultIcon = R.drwable.ic_launcher_BACKGROUND // Set the default animation animStyle = R.style.xxx }Copy the code
Setup2: simple call
ToastBox(this).show("This is ToastBox")
Copy the code
More parameter Settings
// ToastBox().show("This is ToastBox") // ToastBox().setLocation(location.top).show("TOP ToastBox") ToastBox().setLocation(Location.CENTER).show("Center ToastBox") ToastBox().setLocation(Location.BOTTOM).show("Bottom ToastBox().setLocation(location.center).setalpha (0.5f).show(" CENTER ToastBox") // Customize the layout, Pass View or Layout ToastBox().setView(R.layout.custom_toast_Common_1).show("This is Custom View",5000L) // set toast time ToastBox().show("5000L",duration = 5000) // Set xy must be set after location ToastBox().setLocation(location.bottom).setxy (100,200).show("Center ToastBox") ToastBox().setListener(object: ToastClickItf {override fun setOnToastDismissed () {xLog. D (TAG, "toast dismissed")}}). Show (" agghh hem ", 3000 l) // ToastBox().settextStyle (textstyle.gray).show(" GRAY toast ") ToastBox (.) setTextStyle (TextStyle. White.) setXY move (0300). Show (" White Toast ") ToastBox().settextstyle (textstyle.black).setxy (0,600).show(" Black Toast") // set animation ToastBox().setanim (R.stile.miuitoast).show(" ToastBox().seticon (R.drable.icon).show("This is ToastBox")Copy the code
Attached project address:Github.com/xluu233/Toa…
Humble Androider asks for a Star
Write a MVVM rapid development framework (1) basic class encapsulation write a MVVM rapid development framework (2) componentized transformation