Toast Message At the heart of Android's activity

0

I'm creating an application and want to put a message using Toast. But when creating the toast the same is only at the bottom of the activity. To centralize the message I tried to use this command line.

Toast.makeText(MainActivity.this, "Tarefa salva com sucesso!", Toast.LENGTH_SHORT);
            Toast.setGravity(Gravity.CENTER,0,0, null);
            Toast.show();

I'm using the latest version of android studio (3.2)

but is not giving this error

error: method setGravity in class Toast cannot be applied to given types;
required: int,int,int
found: int,int,int,<null>
reason: actual and formal argument lists differ in length
    
asked by anonymous 03.10.2018 / 18:29

1 answer

2

You're starting Toast 3 times doing it this way.

To work, you should do so:

Toast toast = Toast.makeText(MainActivity.this, "Tarefa salva com sucesso!", Toast.LENGTH_LONG);
toast.setGravity(Gravity.CENTER, 0, 0);
toast.show();

Where he creates only one.

    
03.10.2018 / 18:32