LesserPandaToast provides the simplest solution to call different types of progresshuds or toasts and dismiss them in an indicated delay. Users could also customize their own styles.
If you are also interested at Dialog. Please take a look at another library GiantPandaDialog. From these libraries' names, you will find they are used together. Please enjoy them :D
Adding jitpack repository in your project's build.gradle
file:
allprojects {
repositories {
...
maven { url 'https://www.jitpack.io' }
}
}
Adding the following dependency to app build.gradle
file:
dependencies {
implementation 'com.github.nasduck:LesserPandaToast:2.0.1'
}
LesserPandaToast includes two types of Toast:Tip Toast and Loading Toast
4 types of Toast are provided by default:
- Text only
- Success
- Failure
- Warning
// Text only
LesserToastBuilder.show(this, "Toast Default");
// Success
LesserToastBuilder.showSuccess(this); // Image only
LesserToastBuilder.showSuccess(this, "success"); // Image and text
// Failure
LesserToastBuilder.showFailure(this); // Image only
LesserToastBuilder.showFailure(this, "failure"); // Image and text
// Warning
LesserToastBuilder.showWarning(this); // Image only
LesserToastBuilder.showWarning(this, "warning"); // Image and text
Tip Toast is designed based on Android native Toast, so there is no need to hide manually and the display time is the same as that of native Toast.
LesserToastBuilder.getInstance(this)
.setImage(Integer image) // set image
.setAnimation(Integer animation) // set image animation
.setBgColor(Integer bgColor) // set background color
.setCornerRadius(Integer cornerRadius) // set background corner radius
.setPaddingTop(Integer paddingTop) // set top padding
.setPaddingBottom(Integer paddingBottom) // set bottom padding
.setPaddingLeft(Integer paddingLeft) // set left padding
.setPaddingRight(Integer paddingRight) // set right padding
.setPaddingHorizontal(Integer paddingHorizontal) // set horizontal padding
.setPaddingVertical(Integer paddingVertical) // set vertical padding
.setPadding(Integer padding) // set padding
.setText(String text) // set text
.setTextColor(Integer textColor) // set text color
.setTextSize(Integer textSize) // set text size
.setGravity(Integer gravity) // set toast location in window
.setXOffset(Integer xOffset) // set the offset in X
.setYOffset(Integer yOffset) // set the offset in Y
.setDuration(Integer duration) // set duration
.show();
// Loading
DuckToast.showLoading(this); // Image only
DuckToast.showLoading(this, "loading"); // Image and text
After
showLoading
is called, Toast will keep shown until user specifies how it will be dismissed.
Two dismiss solution:
- Dismiss immediately
- Dismiss with delay
LesserToastBuilder.dismiss(); // Dismiss immediately
LesserToastBuilder.dismiss(long delay); // Dismiss with delay (ms)
Customize Toast:
LesserPandaToast.getInstance(this)
.setImage(Integer image) // set image
.setAnimation(Integer animation) // set iamge animation
.setBgColor(Integer bgColor) // set background color
.setCornerRadius(Integer cornerRadius) // set background corner radius
.setPaddingTop(Integer paddingTop) // set top padding
.setPaddingBottom(Integer paddingBottom) // set bottom padding
.setPaddingLeft(Integer paddingLeft) // set left padding
.setPaddingRight(Integer paddingRight) // set right padding
.setPaddingHorizontal(Integer paddingHorizontal) // set horizontal padding
.setPaddingVertical(Integer paddingVertical) // set vertical padding
.setPadding(Integer padding) // set padding
.setText(String text) // set text
.setTextColor(Integer textColor) // set text color
.setTextSize(Integer textSize) // set text size
.show();
LesserPandaToast.dismiss(1500);
- Lihao Zhou
- Chuan DONG
- Si Cheng(Art Designer)
Copyright (2019) Chuan Dong, Lihao Zhou
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.