Skip to content

Instantly share code, notes, and snippets.

@mahdi-malv
Created November 10, 2018 08:27
Show Gist options
  • Save mahdi-malv/94fe53937f4b9a8a240457d3117b8b2c to your computer and use it in GitHub Desktop.
Save mahdi-malv/94fe53937f4b9a8a240457d3117b8b2c to your computer and use it in GitHub Desktop.
Custom Toast
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