Giter VIP home page Giter VIP logo

toastbox's Introduction

ToastBox

ToastBox是一个自定义吐司库,可以实现自定义View、显示时长、显示位置、各种自定义风格,使用便捷。有WindowsManger和系统Toast两种实现方式。

更多实现效果请参考Demo

快速接入:

Add it in your root build.gradle at the end of repositories:

allprojects {
	repositories {
		...
		maven { url 'https://jitpack.io' }
	}
}

Step 2. Add the dependency

dependencies {
    implementation 'com.github.xluu233:ToastBox:0.7.4'
}

快速使用:

stetup1: 初始化(可省略)

        //init可以省略,也可以配置一些全局默认参数
        ToastBox.init(
            duration = 3500L,
            alpha = 1.0f,
            anim = R.style.MiuiToast,
            location = Location.CENTER,
            x = 0,y = 100,
        )

setup2:简单调用

ToastBox.showToast("This is ToastBox")

具体使用

使用setParams()设置自定义参数:

  • 自定义布局,传入view或者layout
ToastBox.setParams(layout = R.layout.toast_custom).showToast("自定义View")
  • 在不同的位置弹出,设置location参数,预定义了三种方式:
ToastBox.setParams(location = Location.BOTTOM).showToast("Bottom ToastBox")
ToastBox.setParams(location = Location.CENTER).showToast("Center ToastBox")
ToastBox.setParams(location = Location.TOP).showToast("TOP ToastBox")
  • 自定义弹出位置XY坐标
ToastBox.setParams(x=100,y=200).showToast("修改XY坐标")
  • 修改透明度:alpha
ToastBox.setParams(alpha = 0.5f).showToast("alpha toast")
  • 设置toast时间:duration
ToastBox.setParams(duration = 5000L).showToast("5000ms")
  • toast消失监听:ToastClickItf
ToastBox.setParams(listener = object :ToastClickItf{
      override fun setOnToastDismissed() {
            Log.d(TAG,"toast dismissed")
      }
}).showToast("事件监听")
  • toast风格样式,预定义的三种样式: ToastTextStyle.Black/White/Gray
ToastBox.setParams(defaultTextStyle = ToastTextStyle.Black).showToast("黑色Toast")
ToastBox.setParams(defaultTextStyle = ToastTextStyle.White,x = 0, y = 300).showToast("白色Toast")
ToastBox.setParams(defaultTextStyle = ToastTextStyle.GRAY,x = 0, y = 600).showToast("灰色Toast")
  • 设置动画,预定义了三种动画:ToastAnim_OPENToastAnim_ALPHAToastAnim_MIUI
ToastBox.setParams(anim = R.style.ToastAnim_OPEN).showToast("动画切换1")
ToastBox.setParams(anim = R.style.ToastAnim_ALPHA, x = 0, y = 300).showToast("动画切换2")

setParams()详细参数

参数 详情 作用
duration 默认 duration:Long = 2500L 弹出时间
location 参考:Location.BOTTOM、 Location.CENTER、Location.TOP 修改弹出位置
x,y 示例::setParams(x=100,y=200) 设置XY坐标
alpha @FloatRange(from = 0.0, to = 1.0),示例:setParams(alpha = 0.5f) 修改透明度
view、layout 示例:setParams(view = XX,layout = R.layout.xx) 自定义view
anim 参考:R.style.ToastAnim_OPENR.style.ToastAnim_ALPHAR.style.ToastAnim_MIUI 设置动画
defaultTextStyle 预定义的三种风格:ToastTextStyle.Black/White/Gray 黑色、白色、灰色 设置Toast风格
textTheme @StyleRes,示例:setParams(textTheme=R.style.xx) 自定义字体主题
backDrawable @DrawableRes,示例:setParams(backDrawable = R.drawable.xx) 设置背景样式
listener ToastClickItf 设置toast消失事件监听

配合Lottie动画库可以做一些好看的toast

success:

fail:

网络错误:

普通信息:

Lottie中有很多看好的动画,你也可以自己设计一个。

Lottie动画
Lottie开发文档

toastbox's People

Contributors

luhongcheng2022 avatar xluu233 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

toastbox's Issues

NoSuchMethodError

ToastBox.showToast(msg,false)

Caused by: java.lang.NoSuchMethodError: No static method metafactory(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite; in class Ljava/lang/invoke/LambdaMetafactory; or its super classes (declaration of 'java.lang.invoke.LambdaMetafactory' appears in /apex/com.android.art/javalib/core-oj.jar)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.