DEV Community ๐Ÿ‘ฉโ€๐Ÿ’ป๐Ÿ‘จโ€๐Ÿ’ป

Sunny k.thakur
Sunny k.thakur

Posted on

Toast message in android

Image descriptionHow to write Toast message in Android I just started learning Android development
what is the right way to write Toast message in java Android

Top comments (3)

Collapse
 
dibasdauliya profile image
Dibas Dauliya • Edited on

You haven't given context in your code. Try this:

Toast.makeText(MainActivity.this, "Toast message", Toast.LENGTH_SHORT).show();
Enter fullscreen mode Exit fullscreen mode

If you want to make your Toast appear for a long time then replace LENGTH_SHORT with LENGTH_LONG.

Read more about Toast and its alternatives at developer.android.com/guide/topics....

Collapse
 
z80asmcoder profile image
z80AsmCoder

You can also use getApplicationContext() instead of MainActivity.this

Collapse
 
sunnythakr profile image
Sunny k.thakur

Thanks Dibas

๐ŸŒš Friends don't let friends browse without dark mode.

Just kidding, it's a personal preference. But you can change your theme, font, etc. in your settings.

The more you know. ๐ŸŒˆ