Giter Site home page Giter Site logo

dongfang-wangdaren / universaltoast Goto Github PK

View Code? Open in Web Editor NEW

This project forked from bboylin/universaltoast

1.0 1.0 0.0 1.75 MB

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

Java 100.00%

universaltoast's Introduction

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.5'
}
  • 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 unnecessary to request permission。

minSdkVersion>=14

thanks to : ToastCompat

universaltoast's People

Contributors

bboylin avatar

Stargazers

DONGFANG WANGDAREN | 东方 旺大人 avatar

Watchers

DONGFANG WANGDAREN | 东方 旺大人 avatar

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.