How to set the font for toast?

I can set my own font to a text view like this

Typeface typeface = Typeface.createFromAsset(context.getAssets(),"fonts/akshar.ttf"); setTypeface(typeface); 

How can I set the same for the default toast so that I can display the locale text in the toast messages. I can set Gravity, duration, but not font.

Thanks in advance.

+4
source share
2 answers

You can create a custom toast like:

  LayoutInflater inflater = getLayoutInflater(); View layout = inflater.inflate(R.layout.toast_layout, (ViewGroup) findViewById(R.id.toast_layout_root)); TextView text = (TextView) layout.findViewById(R.id.text); text.setText("Hello! This is a custom toast!"); Typeface typeface = Typeface.createFromAsset(context.getAssets(),"fonts/akshar.ttf"); text.setTypeface(typeface); Toast toast = new Toast(getApplicationContext()); toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0); toast.setDuration(Toast.LENGTH_LONG); toast.setView(layout); toast.show(); 

and for more details on how we create custom Toast, see CustomToastView

+3
source

Toast has a setView () method, so you can set the font for the TextView and add the same TextView to Toast using

 toast.setView(textview); 
+1
source

All Articles