自定义Toast的使用:
首先在Gradle:
添加:
allprojects { repositories { maven { url "https://jitpack.io" } } }
compile 'com.github.GrenderG:Toasty:1.2.5'public void toast_show(View view) { switch (view.getId()){ case R.id.btn_one: Toasty.success(this, "Success!", Toast.LENGTH_SHORT, true).show(); break; case R.id.btn_two: Toasty.info(this, "Here is some info for you.", Toast.LENGTH_SHORT, true).show(); break; case R.id.btn_three: Toasty.warning(this, "Beware of the dog.", Toast.LENGTH_SHORT, true).show(); break; case R.id.btn_four: Toasty.normal(this, "Normal toast w/o icon").show(); break; case R.id.btn_five: Drawable icon = getResources().getDrawable(R.mipmap.ic_launcher_round); Toasty.normal(this, "Normal toast w/ icon", icon).show(); break;
可自定义属性:”
Toasty.Config.getInstance() .setErrorColor(@ColorInt int errorColor) // optional .setInfoColor(@ColorInt int infoColor) // optional .setSuccessColor(@ColorInt int successColor) // optional .setWarningColor(@ColorInt int warningColor) // optional .setTextColor(@ColorInt int textColor) // optional .tintIcon(boolean tintIcon) // optional (apply textColor also to the icon) .setToastTypeface(@NonNull Typeface typeface) // optional .setTextSize(int sizeInSp) // optional .apply(); // required
效果图: