Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change Toast Font

Tags:

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.

like image 601
Ye Lin Aung Avatar asked May 30 '10 21:05

Ye Lin Aung


People also ask

How do you change the text color on toast?

If You need to change the color of the view created then you need to use getView(). getBackground(). setColorFilter() function. If you need to add some icon along with the message in the toast view then you need to first get an instance of the TextView in the toast using getView().


2 Answers

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!

like image 100
DritanX Avatar answered Oct 21 '22 19:10

DritanX


From the official documentation:

Create your custom ToastView

If a simple text message isn't enough, you can create a customized layout for your toast notification. To create a custom layout, define a View layout, in XML or in your application code, and pass the root View object to the setView(View) method.

Following the link to the official Google Documentation will provide examples.

like image 38
RoflcoptrException Avatar answered Oct 21 '22 21:10

RoflcoptrException