Skip to content

Instantly share code, notes, and snippets.

@ketzalv
Last active December 4, 2019 22:19
Show Gist options
  • Save ketzalv/9b1ad0d8f5a8b488c53e97a98235664a to your computer and use it in GitHub Desktop.
Save ketzalv/9b1ad0d8f5a8b488c53e97a98235664a to your computer and use it in GitHub Desktop.
A simple class that list the methods to show messages in Android
import android.content.Context;
import android.view.View;
import android.widget.Toast;
import com.google.android.material.snackbar.Snackbar;
public class UiUtils {
public static void showToast(String message, Context context) {
Toast.makeText(context, message, Toast.LENGTH_SHORT).show();
}
public static void showSnackBar(View coordinatorLayout, String message, String actionName, View.OnClickListener listener) {
Snackbar.make(coordinatorLayout, message, Snackbar.LENGTH_LONG).setAction(actionName, listener).show();
}
public static void showSnackBar(View coordinatorLayout, String message) {
Snackbar.make(coordinatorLayout, message, Snackbar.LENGTH_LONG).show();
}
public static void showSnackBar(View coordinatorLayout, String message, String actionName, int duration, View.OnClickListener listener) {
Snackbar.make(coordinatorLayout, message, duration).setAction(actionName, listener).show();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment