public static Toast Custom(Context context, string message, Drawable icon, Color textColor, Color tintColor, ToastLength duration, bool withIcon, bool shouldTint) { var toast = new Toast(context); var toastLayout = ((LayoutInflater)context.GetSystemService(Context.LayoutInflaterService)).Inflate(Resource.Layout.ToastLayout, null); var toastIcon = toastLayout.FindViewById <ImageView>(Resource.Id.ToastIcon); var toastTextView = toastLayout.FindViewById <TextView>(Resource.Id.ToastText); Drawable drawableFrame; if (shouldTint) { drawableFrame = ToastyUtils.Tint9PatchDrawableFrame(context, tintColor); } else { drawableFrame = ToastyUtils.GetDrawable(context, Resource.Drawable.toast_frame); } ToastyUtils.SetBackground(toastLayout, drawableFrame); if (withIcon) { if (icon == null) { throw new Exception("Avoid passing 'icon' as null if 'withIcon' is set to true"); } ToastyUtils.SetBackground(toastIcon, icon); } else { toastIcon.Visibility = ViewStates.Gone; } toastTextView.SetTextColor(textColor); toastTextView.Text = message; toastTextView.SetTypeface(Typeface.Create(TOAST_TYPEFACE, TypefaceStyle.Normal), TypefaceStyle.Normal); toast.View = toastLayout; toast.Duration = duration; return(toast); }
public static Toast Error(Context context, string message, ToastLength duration = ToastLength.Short, bool withIcon = true) { return(Custom(context, message, ToastyUtils.GetDrawable(context, Resource.Drawable.ic_clear_white_48dp), DEFAULT_TEXT_COLOR, ERROR_COLOR, duration, withIcon, true)); }
public static Toast Custom(Context context, string message, int iconRes, Color textColor, Color tintColor, ToastLength duration, bool withIcon, bool shouldTint) { return(Custom(context, message, ToastyUtils.GetDrawable(context, iconRes), textColor, tintColor, duration, withIcon, shouldTint)); }
public static Toast Info(Context context, string message, ToastLength duration = ToastLength.Short, bool withIcon = true) { return(Custom(context, message, ToastyUtils.GetDrawable(context, Resource.Drawable.ic_info_outline_white_48dp), DEFAULT_TEXT_COLOR, INFO_COLOR, duration, withIcon, true)); }