Toast in Android is a small popup message used to show brief feedback to the user. It appears above the app content for a short time and then disappears automatically, without requiring the user to close it.
In this Kotlin Android tutorial, we will learn how to show a Toast message, how Toast.makeText() works, how to display a Toast on button click, and when a Toast is the right choice for user feedback.
Android Toast syntax in Kotlin
The basic Kotlin syntax for Android Toast is shown below. You create a Toast using Toast.makeText() and then call show() to display it.
Toast.makeText(this, "Hi there! This is a Toast.", Toast.LENGTH_SHORT).show()
Toast.makeText(this, "Hi there! This is a Toast.", Toast.LENGTH_LONG).show()
In the examples above, makeText() takes three main arguments: the Context, the message text, and the duration. The duration can be Toast.LENGTH_SHORT or Toast.LENGTH_LONG. The show() method finally displays the Toast on the screen.
Toast.makeText() parameters in Android Kotlin
The Toast.makeText() call is small, but each argument has a clear role.
| Parameter | What it means | Example value |
|---|---|---|
context | The current Activity, Fragment context, or application context used to create the Toast. | this, applicationContext, requireContext() |
text | The message to show to the user. | "Saved successfully" |
duration | How long the Toast should stay visible. | Toast.LENGTH_SHORT or Toast.LENGTH_LONG |
For short confirmation messages such as “Saved”, “Copied”, or “Item deleted”, Toast.LENGTH_SHORT is usually enough. Use Toast.LENGTH_LONG only when the message needs slightly more reading time.
Kotlin Android Toast example with Button click
Android Toast – Kotlin Example : In this Android Tutorial, we shall learn to make a Toast with example Android Applications.
We shall use following two tutorials in demonstrating Toast.
Example Android Application with Kotlin Support Create Activity with name ‘ToastActivity’.
Button OnclickListener On click of a button, we shall display the Toast. This scenario could be generalised as displaying a piece of text when an event occurs.
A typical toast is shown below :

Following is the code for ToastActivity.kt and activity_toast.xml.
activity_toast.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.tutorialkart.myapplication.ToastActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:padding="25dp"
android:orientation="horizontal">
<Button
android:id="@+id/btn_click_me"
android:background="@drawable/btn_round_edge"
android:text="Click me for Toast"
android:textAllCaps="false"
android:padding="10dp"
android:textSize="25dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</android.support.constraint.ConstraintLayout>
ToastActivity.kt
package com.tutorialkart.myapplication
import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.widget.Button
import android.widget.Toast
class ToastActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_toast)
var btn_click_me = findViewById(R.id.btn_click_me) as Button
btn_click_me.setOnClickListener {
// make a toast on button click event
Toast.makeText(this, "Hi there! This is a Toast.", Toast.LENGTH_LONG).show()
}
}
}
The sample above uses the older Android support library package names because it belongs to an earlier Android project setup. In newer Android projects, you will usually use AndroidX imports such as androidx.appcompat.app.AppCompatActivity. The Toast syntax itself remains the same.
Updated AndroidX Toast Activity example in Kotlin
For a modern AndroidX Activity, the same button-click Toast can be written like this.
package com.tutorialkart.myapplication
import android.os.Bundle
import android.widget.Button
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
class ToastActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_toast)
val button = findViewById<Button>(R.id.btn_click_me)
button.setOnClickListener {
Toast.makeText(this, "Hi there! This is a Toast.", Toast.LENGTH_SHORT).show()
}
}
}
In an Activity, this usually works as the context because the Activity is itself a Context. You may also use applicationContext for simple Toast messages.
Show Toast from a Fragment in Kotlin
If you are showing a Toast from a Fragment, use the Fragment context instead of Activity this. A common Kotlin pattern is to use requireContext() when the Fragment is attached.
Toast.makeText(requireContext(), "Fragment Toast message", Toast.LENGTH_SHORT).show()
If there is a chance that the Fragment is not attached at the time of the call, use a safer nullable context check.
context?.let {
Toast.makeText(it, "Fragment Toast message", Toast.LENGTH_SHORT).show()
}
Run the Android Toast example app
When the application is built and run on an Android device,

Click on the button, “Click me for Toast” to display the Toast

Try changing the Toast duration from Toast.LENGTH_LONG to Toast.LENGTH_SHORT and observe the display duration differences.
When to use Toast messages in Android apps
Use a Toast when the app needs to show a short, non-critical message. A Toast is suitable for quick feedback such as “Copied to clipboard”, “Settings saved”, or “No internet connection”.
- Use Toast for brief status messages that do not need user action.
- Do not use Toast for important errors that the user must read carefully.
- Do not place action buttons inside a Toast.
- For messages that need an action, consider Snackbar instead.
- Keep the message short because Toast disappears automatically.
The official Android documentation for Toasts and the Toast API reference are useful references when checking platform behavior and available methods.
Common Toast mistakes in Kotlin Android
- Forgetting show():
Toast.makeText()only creates the Toast. It will not appear unlessshow()is called. - Using the wrong context: In an Activity,
thisis usually fine. In a Fragment, userequireContext()or a safe nullable context. - Writing long messages: Toasts are temporary, so long text may disappear before the user finishes reading.
- Using Toast for critical information: Important validation errors or decisions should be shown in the screen UI, a dialog, or another persistent component.
- Showing too many Toasts: Repeated Toasts can make the app feel noisy and can hide more useful feedback.
Quick QA checklist for this Android Toast tutorial
- The Kotlin file imports
android.widget.Toast. - The Toast code calls
show()afterToast.makeText(). - The context matches the place where the Toast is shown: Activity, Fragment, or application context.
- The Toast message is short enough to read before it disappears.
- The example uses
Toast.LENGTH_SHORTorToast.LENGTH_LONG, not a custom unsupported duration value. - The Toast is used for brief feedback, not for a message that requires user action.
Android Toast Kotlin FAQs
How do I show a Toast in Kotlin Android?
Use Toast.makeText(context, message, duration).show(). In an Activity, the context can be this. For example: Toast.makeText(this, "Saved", Toast.LENGTH_SHORT).show().
What is the difference between Toast.LENGTH_SHORT and Toast.LENGTH_LONG?
Toast.LENGTH_SHORT shows the message for a shorter time, while Toast.LENGTH_LONG keeps it visible for a little longer. Use the short duration for simple confirmation messages and the long duration when the text needs more reading time.
Why is my Android Toast not showing?
Check whether you called show(), imported android.widget.Toast, and passed a valid context. In a Fragment, using Activity this directly can be a common mistake; use requireContext() or context?.let { ... } instead.
Can I show a Toast from a Fragment in Kotlin?
Yes. Use Toast.makeText(requireContext(), "Message", Toast.LENGTH_SHORT).show() when the Fragment is attached. If the Fragment context may be null, use context?.let { Toast.makeText(it, "Message", Toast.LENGTH_SHORT).show() }.
Should I use Toast or Snackbar in Android?
Use Toast for short feedback that does not need action. Use Snackbar when the message is related to the current screen and may need an action, such as “Undo”.
Conclusion
In this Kotlin Android Tutorial, we learned how to display a Toast upon some user interaction. We also looked at Toast syntax, duration values, Activity and Fragment examples, common mistakes, and practical use cases for Toast messages in Android apps.
TutorialKart.com