-
-
Save suclike/bf1cf9eb2673e48fd8dd to your computer and use it in GitHub Desktop.
Wrapper class to customise android.support.design snack bar!
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
/** | |
* Snackbars | |
* | |
* @author The Finest Artist | |
*/ | |
public class Snackbars { | |
private Snackbars() { | |
} | |
private static int getColor(@NonNull Context context, @ColorRes int color) { | |
return context.getResources().getColor(color); | |
} | |
public static void show(@NonNull Activity activity, final String message) { | |
final View content = activity.getWindow().getDecorView().findViewById(android.R.id.content); | |
if (content == null) | |
return; | |
Snackbar snackbar = Snackbar.make(content, message, Snackbar.LENGTH_LONG); | |
snackbar.setActionTextColor(getColor(activity, R.color.orange)); | |
View view = snackbar.getView(); | |
view.setBackgroundColor(getColor(activity, R.color.white)); | |
TextView textView = (TextView) view.findViewById(android.support.design.R.id.snackbar_text); | |
textView.setTextColor(getColor(activity, R.color.orange)); | |
textView.setLineSpacing(0, 1.1f); | |
textView.setIncludeFontPadding(false); | |
snackbar.show(); | |
} | |
public static void alert(@NonNull final Activity activity, final String message) { | |
final View content = activity.getWindow().getDecorView().findViewById(android.R.id.content); | |
if (content == null) | |
return; | |
Snackbar snackbar = Snackbar.make(content, message, Snackbar.LENGTH_LONG); | |
snackbar.setActionTextColor(getColor(activity, R.color.white)); | |
View view = snackbar.getView(); | |
view.setBackgroundColor(getColor(activity, R.color.orange)); | |
TextView textView = (TextView) view.findViewById(android.support.design.R.id.snackbar_text); | |
textView.setTextColor(getColor(activity, R.color.white)); | |
textView.setLineSpacing(0, 1.1f); | |
textView.setIncludeFontPadding(false); | |
snackbar.show(); | |
} | |
}//end of class |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment