Skip to content

Instantly share code, notes, and snippets.

@rezaiyan
Created September 18, 2017 10:02
Show Gist options
  • Save rezaiyan/2dcb826c3619eeda027e87b3b9a6be7d to your computer and use it in GitHub Desktop.
Save rezaiyan/2dcb826c3619eeda027e87b3b9a6be7d to your computer and use it in GitHub Desktop.
Custom Toast
public class CustomToast {
public static void showToast(Context context,String message) {
Toast toast = Toast.makeText(context, message, Toast.LENGTH_SHORT);
toast.setGravity(Gravity.BOTTOM, toast.getXOffset() / 3, toast.getYOffset() / 3);
TextView textView = new TextView(context);
textView.setBackgroundColor(Color.DKGRAY);
textView.setTextColor(Color.WHITE);
textView.setTypeface(FontManager.Iransens(context));
textView.setPadding(10, 10, 10, 10);
textView.setText(message);
toast.setView(textView);
toast.show();
}
}
public class FontManager {
public static Typeface Iransens(Context context) {
return Typeface.createFromAsset(context.getAssets(), "fonts/IRANSansMobile.ttf");
}
public static Typeface Iransens_numeric(Context context) {
return Typeface.createFromAsset(context.getAssets(), "fonts/IRANSansMobile(FaNum)_Bold.ttf");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment