Toast in Android using Kotlin
Toast is used to show small text messages on the screen for short time. The toast message stays for about 2, 3, or 5 seconds on screen after that it disappears automatically. The main motive of the toast message is to inform the user such as to warn a user who is trying to enter the number in the name field of the form. There is a dedicated Toast class available in Android SDK to make and show toast messages. The Toast class contains a static method called makeText() that is used to make a toast message. Check out the syntax to create and show a toast message.
Toast.makeText(Context, String message, Toast duration).show();
As in the above syntax, you can clearly see we have used another method called show() to show a toast message on the screen. To mention toast duration static variables LENGTH_SHORT or LENGTH_LONG are available in the Toast class.
Example program to show simple toast message:
Toast.makeText(this, "Hello! This is a Toast message.", Toast.LENGTH_LONG).show()
Spread the love:
Please share this page on social media with your friends..