Android Toast自定義

自定義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
效果圖:

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章