Last active
November 7, 2017 20:14
-
-
Save JoseBueno/8b81a599c9a95fcb963c to your computer and use it in GitHub Desktop.
Convenience wrapper for Android Toast
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.buenocodigo.utilities; | |
import android.annotation.SuppressLint; | |
import android.app.Activity; | |
import android.view.Gravity; | |
import android.widget.Toast; | |
/** | |
* | |
* Created by jbueno on 5/7/2015. | |
*/ | |
@SuppressWarnings("SameParameterValue") | |
public class Toaster { | |
public static void makeToast(Activity activity, String message) { | |
getToast(activity, message, Toast.LENGTH_SHORT, Gravity.CENTER).show(); | |
} | |
public static void makeToast(Activity activity, String message, int duration) { | |
getToast(activity, message, duration, Gravity.CENTER).show(); | |
} | |
public static void makeToast(Activity activity, String message, int duration, int gravity) { | |
getToast(activity, message, duration, gravity).show(); | |
} | |
private static Toast getToast(Activity activity, String message, int duration, int gravity) { | |
@SuppressLint("ShowToast") Toast toast = Toast.makeText(activity, message, duration); | |
toast.setGravity(gravity, toast.getXOffset() /2, toast.getYOffset() /2); | |
return toast; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment