|
| 1 | +toast提供最简单的方法来调用各类简单的toast,同时提供了自定义方法来定义不同的toast样式。 |
| 2 | + |
| 3 | +## 依赖 |
| 4 | +步骤一:在项目的build.gradle中添加jitpack |
| 5 | +``` |
| 6 | +allprojects { |
| 7 | + repositories { |
| 8 | + ... |
| 9 | + maven { url 'https://www.jitpack.io' } |
| 10 | + } |
| 11 | +} |
| 12 | +``` |
| 13 | +步骤二:添加依赖项 |
| 14 | +``` |
| 15 | +dependencies { |
| 16 | + implementation |
| 17 | +} |
| 18 | +``` |
| 19 | + |
| 20 | +## 使用方式 |
| 21 | +### 调用文字Toast |
| 22 | +```java |
| 23 | +DuckToast.show(this, "Toast Default"); |
| 24 | +``` |
| 25 | +### 调用提示Toast |
| 26 | +#### Success |
| 27 | +```java |
| 28 | +DuckToast.showSuccess(this); // 只有图标,不含文字 |
| 29 | +DuckToast.showSuccess(this, "success"); // 包含图标和文字 |
| 30 | +``` |
| 31 | +#### Failure |
| 32 | +```java |
| 33 | +DuckToast.showFailure(this); // 只有图标,不含文字 |
| 34 | +DuckToast.showFailure(this, "failure"); // 包含图标和文字 |
| 35 | +``` |
| 36 | +#### Warning |
| 37 | +```java |
| 38 | +DuckToast.showWarning(this); // 只有图标,不含文字 |
| 39 | +DuckToast.showWarning(this, "warning"); // 包含图标和文字 |
| 40 | +``` |
| 41 | +#### Loading |
| 42 | +```java |
| 43 | +DuckToast.showLoading(this); // 只有图标,不含文字 |
| 44 | +DuckToast.showLoading(this, "loading"); // 包含图标和文字 |
| 45 | +``` |
| 46 | + |
| 47 | +### 隐藏Toast |
| 48 | +toast有一个开关的控制,所有的toast调用显示都属于开的过程,而toast的隐藏需要调用方法: |
| 49 | +```java |
| 50 | +DuckToast.dismiss(); // 使toast立刻消失 |
| 51 | +DuckToast.dismiss(long delay); // 使toast在延迟delay的时间后消失 |
| 52 | +``` |
| 53 | + |
| 54 | +### 自定义Toast |
| 55 | +在创建自定义toast时,建议进行进一步封装方便调用 |
| 56 | +```java |
| 57 | +ToastBuilder.getInstance(this) |
| 58 | + .setImage(Integer image) // 设置图片,如果未设置,则toast中的图片不显示,图片相关设置不生效 |
| 59 | + .setAnimation(Integer animation) // 设置图片的动画 |
| 60 | + .setBgColor(Integer bgColor) // 设置背景的颜色 |
| 61 | + .setCornerRadius(Integer cornerRadius) // 设置背景的圆角 |
| 62 | + .setPaddingHorizontal(Integer paddingHorizontal) // 设置水平的padding |
| 63 | + .setPaddingVertical(Integer paddingVertical) // 设置竖直的padding |
| 64 | + .setText(String text) // 设置文字,如果未设置,则toast中的文字不显示,文字相关设置不生效 |
| 65 | + .setTextColor(Integer textColor) // 设置文字颜色 |
| 66 | + .setTextSize(Integer textSize) // 设置文字大小 |
| 67 | + .show(); |
| 68 | +ToastBuilder.dismiss(1500); |
| 69 | +``` |
| 70 | + |
| 71 | +## 贡献 |
| 72 | + |
| 73 | +* [Lihao Zhou](https://github.com/redrain39) |
| 74 | +* [Chuan DONG](https://github.com/DONGChuan) |
| 75 | +* [Si Cheng ]([email protected])(设计师) |
| 76 | + |
| 77 | +## LICENSE |
| 78 | +``` |
| 79 | + Copyright (2019) Chuan Dong, Lihao Zhou |
| 80 | +
|
| 81 | + Licensed under the Apache License, Version 2.0 (the "License"); |
| 82 | + you may not use this file except in compliance with the License. |
| 83 | + You may obtain a copy of the License at |
| 84 | +
|
| 85 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 86 | +
|
| 87 | + Unless required by applicable law or agreed to in writing, software |
| 88 | + distributed under the License is distributed on an "AS IS" BASIS, |
| 89 | + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 90 | + See the License for the specific language governing permissions and |
| 91 | + limitations under the License. |
| 92 | +``` |
0 commit comments