Skip to content

Instantly share code, notes, and snippets.

@blazvantur
Created January 29, 2018 14:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save blazvantur/2a4918e429ec5adeaa3c531c056ba406 to your computer and use it in GitHub Desktop.
Save blazvantur/2a4918e429ec5adeaa3c531c056ba406 to your computer and use it in GitHub Desktop.
public static Toast makeText(Context context, String message, int duration, String color) {
LayoutCustomToastBinding binding =
DataBindingUtil.inflate(LayoutInflater.from(context), R.layout.layout_custom_toast,
null, false);
binding.tvMessage.setText(message);
int roundRadius = (int) convertDpToPixel(context, 35);
GradientDrawable gradientDrawable = new GradientDrawable();
gradientDrawable.setColor(Color.parseColor(color));
gradientDrawable.setCornerRadius(roundRadius);
binding.content.setBackground(gradientDrawable);
Toast toast = new Toast(context);
toast.setDuration(duration);
toast.setView(binding.getRoot());
return toast;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment