原创作品,转载请注明出处
欢迎来到ToastZ!
之前写过一个"ToastUtil" 让你的Toast更简单,近期对ToastUtil有进行了一些更新,最终出现了ToastZ。
ToastZ是一个可自定义的Toast,颇具个性,使用简洁而功能强大。优点请亲自体验,细节请阅读文档和源码。
由于目前ToastZ处于beta阶段,所以会较频繁更新,频繁程度在于你的 issues https://github.com/duyangs/ToastZ/issues
集成方式:
- Gradle
步骤1:将它添加到Project build.gradle 的根目录中:
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
步骤2.在module中添加dependency:
dependencies {
implementation 'com.github.duyangs:ToastZ:release'
}
- Maven
步骤1. 添加JitPack repository到你的build file
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
步骤2. 添加dependency
<dependency>
<groupId>com.github.duyangs</groupId>
<artifactId>ToastZ</artifactId>
<version>release</version>
</dependency>
配置方式:
- 常规方式
ToastZLib.init(this)//初始化,Context
- 进阶方式
//步骤一
ToastZLib.init(this)//初始化,Context
//步骤二
ToastZ.with().setGravity(Gravity.TOP)//设置Toast显示位置, Gravity.CENTER、Gravity.TOP or Gravity.BOTTOM.
.setSuccessColor(Color.parseColor("#909090"))//设置“成功”模式下 Toast背景颜色,@ColorInt
.setInfoColor(Color.parseColor("#909090"))//设置“提示”模式下 Toast背景颜色,@ColorInt
.setWarningColor(Color.parseColor("#909090"))//设置“警告”模式下 Toast背景颜色,@ColorInt
.setErrorColor(Color.parseColor("#909090"))//设置“错误”模式下 Toast背景颜色,@ColorInt
.setTextSize(16)//设置Toast文字大小,单位:sp
.setTextColor(Color.parseColor("#FFFFFF"))//设置Toast文字颜色,@ColorInt
.setToastTypeface(Typeface.create("sans-serif-condensed", Typeface.NORMAL))//设置Toast字体,Typeface
.tintIcon(true)//设置是否显示Toast Icon,true or false
.apply()
//重置
ToastZ.with().reset()
使用方式:
- 常规方式
ToastZ.normal("normal")//只显示文字信息,无图标模式
ToastZ.success(R.string.success)//成功模式
ToastZ.warning("warning")//警告模式
ToastZ.error("error")//错误模式
ToastZ.cancelToast()//手动取消Toast
- 进阶方式
//normal
ToastZ.normal(msg: Any)
ToastZ.normal(msg: Any, gravity: Int)
ToastZ.normal(msg: Any, gravity: Int, duration: Int)
ToastZ.normal(msg: Any, gravity: Int, duration: Int, icon: Drawable?)
/**
* @param msg Any Need to show information,only StringRes or String.
* @param gravity Toast display position, Gravity.CENTER、Gravity.TOP or Gravity.BOTTOM.
* @param duration Toast display time, Toast.LENGTH_SHORT or Toast.LENGTH_LONG.
* @param icon Icon of Toast, only Drawable
* @param withIcon Whether to show Toast icon,true or false.
*/
ToastZ.normal(msg: Any, gravity: Int, duration: Int, icon: Drawable?, withIcon: Boolean)
//success
ToastZ.success(msg: Any)
ToastZ.success(msg: Any, gravity: Int)
ToastZ.success(msg: Any, gravity: Int, duration: Int)
/**
* @param msg Any Need to show information,only StringRes or String.
* @param gravity Toast display position, Gravity.CENTER、Gravity.TOP or Gravity.BOTTOM.
* @param duration Toast display time, Toast.LENGTH_SHORT or Toast.LENGTH_LONG.
* @param withIcon Whether to show Toast icon,true or false.
*/
ToastZ.success(msg: Any, gravity: Int, duration: Int, withIcon: Boolean)
//info
ToastZ.info(msg: Any)
ToastZ.info(msg: Any, gravity: Int)
ToastZ.info(msg: Any, gravity: Int, duration: Int)
/**
* @param msg Any Need to show information,only StringRes or String.
* @param gravity Toast display position, Gravity.CENTER、Gravity.TOP or Gravity.BOTTOM.
* @param duration Toast display time, Toast.LENGTH_SHORT or Toast.LENGTH_LONG.
* @param withIcon Whether to show Toast icon,true or false.
*/
ToastZ.info(msg: Any, gravity: Int, duration: Int, withIcon: Boolean)
//warning
ToastZ.warning(msg: Any)
ToastZ.warning(msg: Any, gravity: Int)
ToastZ.warning(msg: Any, gravity: Int, duration: Int)
/**
* @param msg Any Need to show information,only StringRes or String.
* @param gravity Toast display position, Gravity.CENTER、Gravity.TOP or Gravity.BOTTOM.
* @param duration Toast display time, Toast.LENGTH_SHORT or Toast.LENGTH_LONG.
* @param withIcon Whether to show Toast icon,true or false.
*/
ToastZ.warning(msg: Any, gravity: Int, duration: Int, withIcon: Boolean)
//error
ToastZ.error(msg: Any)
ToastZ.error(msg: Any, gravity: Int)
ToastZ.error(msg: Any, gravity: Int, duration: Int)
/**
* @param msg Any Need to show information,only StringRes or String.
* @param gravity Toast display position, Gravity.CENTER、Gravity.TOP or Gravity.BOTTOM.
* @param duration Toast display time, Toast.LENGTH_SHORT or Toast.LENGTH_LONG.
* @param withIcon Whether to show Toast icon,true or false.
*/
ToastZ.error(msg: Any, gravity: Int, duration: Int, withIcon: Boolean)
//custom
ToastZ.custom(msg: Any, @DrawableRes icon: Drawable, @ColorInt tintColor: Int, duration: Int)
ToastZ.custom(msg: Any, gravity: Int, @DrawableRes icon: Drawable, @ColorInt tintColor: Int, duration: Int)
ToastZ.custom(msg: Any, gravity: Int, @DrawableRes icon: Drawable, @ColorInt tintColor: Int, duration: Int, withIcon: Boolean)
/**
* @param msg Any Need to show information,only StringRes or String.
* @param gravity Toast display position, Gravity.CENTER、Gravity.TOP or Gravity.BOTTOM.
* @param iconRes Toast icon,only DrawableRes.
* @param tintColor Toast background color, only ColorInt.
* @param duration Toast display time, Toast.LENGTH_SHORT or Toast.LENGTH_LONG.
* @param withIcon Whether to show Toast icon,true or false.
* @param shouldTint Whether to modify the Toast background,true or false.
*/
ToastZ.custom(msg: Any, gravity: Int, @DrawableRes iconRes: Int, @ColorInt tintColor: Int, duration: Int,
withIcon: Boolean, shouldTint: Boolean)
这只是个最简单示例,更多功能示例会逐渐补充
更多内容可查看源码https://github.com/duyangs/ToastZ,欢迎指正,希望对你有所帮助
网友评论