Skip to content

简洁优雅可点击的toast控件,仿手机百度9.0,无BadTokenException风险。An elegant and flexible toast which can handle click event and avoid BadTokenException

Notifications You must be signed in to change notification settings

xin78693304/UniversalToast

 
 

Repository files navigation

UniversalToast:an elegant and flexible toast which can handle click event

中文版文档请戳:这里

features

  • elegant & flexible
  • can handle click event & custom duration (by adding view with WindowManager)
  • auto avoid BadTokenException in android N (which cannot be caught in you application)

Usages

  • step 1 : add dependency
allprojects {
    repositories {
        ......
        maven { url 'https://jitpack.io' }
    }
}

dependencies {
    ......
    compile 'com.github.bboylin:UniversalToast:v1.0.4'
}
  • step 2 : simply use it like system toast
UniversalToast.makeText(context, text, duration).show();
UniversalToast.makeText(context, text, duration,type).show();

duration must be either UniversalToast.LENGTH_LONG or UniversalToast.LENGTH_SHORT, type must be one of UniversalToast.UNIVERSAL ,UniversalToast.EMPHASIZE,UniversalToast.CLICKABLE, by default UniversalToast.UNIVERSAL.

from left to right : UNIVERSALEMPHASIZECLICKABLE , you can set the icon and text as you like 。

  • further api:

//example
UniversalToast.makeText(context, text, UniversalToast.LENGTH_SHORT, UniversalToast.CLICKABLE)
              .setGravity(gravity,xOffset,yOffset)
              .setBackground(drawable)//set the background drawable as you like
              .setColor(R.color.my_color)//set the background color as you like
              .setIcon(R.drawable.my_ic)// set the icon as you like (it's visibility is gone until you set icon)
              .setClickCallBack(text,R.drawable.my_btn,onClickListener)
              .show();

it has been provided 3 basically default icons for you,you can use showSuccess(),showWarning() or showError() instead of show()

from left to right : showSuccessshowWarningshowError (the pics above shows the type EMPHASIZE ,you can also use CLICKABLE or UNIVERSAL

notice:

using UniversalToast.CLICKABLE on android O requires permission :

<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />

Refer to demo about how to request permissions dynamically on android O. with system versions below Android 8.0,it's ok if you don't want to request permission dynamically,but it's also required to request permission staticly in AndroidManifest.xml

minSdkVersion>=14

thanks to : ToastCompat

About

简洁优雅可点击的toast控件,仿手机百度9.0,无BadTokenException风险。An elegant and flexible toast which can handle click event and avoid BadTokenException

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Java 100.0%