Change Toast Font

Ye Lin Aung picture Ye Lin Aung · May 30, 2010 · Viewed 25.3k times · Source

Currently, I'm trying to develop an app. and I don't know how to change the Toast font. .

 final OnClickListener clickListener = new OnClickListener() {

    public void onClick(View v) {
            try {
                Toast.makeText(nova.this,"Hello", 500000).show();
            }
            catch (Exception e) {
                Toast.makeText(nova.this,"Exception:" +e, 500000);
            }
        }
    };

I want to change the text "Hello" with custom font I've tried with TypeFace.

and Then, I want to set a variable at the place "TextClicked" .. I've tried with a local variable .. but it doesn't work

any help with example source code will be really great for me.

Answer

DritanX picture DritanX · Mar 29, 2013

The answer is here: https://stackoverflow.com/a/13231981

After refactoring a little:

    Toast toast = Toast.makeText(context, R.string.yummyToast, Toast.LENGTH_SHORT);
    LinearLayout toastLayout = (LinearLayout) toast.getView();
    TextView toastTV = (TextView) toastLayout.getChildAt(0);
    toastTV.setTextSize(30);
    toast.show();

This worked for me like a charm!