Created
November 10, 2018 08:27
-
-
Save mahdi-malv/94fe53937f4b9a8a240457d3117b8b2c to your computer and use it in GitHub Desktop.
Custom Toast
This file contains hidden or 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
public static void toast(Context context) { | |
Toast toast = Toast.makeText(context, "This is a Toast.", Toast.LENGTH_SHORT); | |
View toastView = toast.getView(); | |
TextView toastMessage = (TextView) toastView.findViewById(android.R.id.message); | |
toastMessage.setTextSize(19); | |
toastMessage.setTextColor(Color.BLACK); | |
toastMessage.setGravity(Gravity.CENTER); | |
toastMessage.setCompoundDrawablesWithIntrinsicBounds(R.drawable.icon_small, 0, 0, 0);// Add an icon to textView | |
toastMessage.setCompoundDrawablePadding(16); // Add padding to icon | |
toastView.setBackgroundColor(Color.WHITE); | |
toast.setGravity(Gravity.TOP, 0, 0); | |
toast.show(); | |
} | |
// Not so customized is it? :|, I'll make it better next time. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment