---
title: "Create custom toast notification in android"  
description: "In Android, Toast is a notification message that pop up, display a certain amount of time, and automatically fades in and out.Generally it is use for"  
author: "Manoj Pandey"  
published: 2015-07-17  
updated: 2018-03-13  
canonical: https://www.mindstick.com/blog/10925/create-custom-toast-notification-in-android  
category: "android"  
tags: ["android", "android styles"]  
reading_time: 3 minutes  

---

# Create custom toast notification in android

In Android, Toast is a notification message that [pop up](https://www.mindstick.com/forum/346/how-to-show-a-pop-up-messagebox), display a certain amount of time, and automatically fades in and out.

Generally it is use for to show error, warnings or success notification for user.

A toast is a view containing a quick little message for the user. The toast class helps you create and show those.

When the view is shown to the user, appears as a [floating](https://www.mindstick.com/articles/85595/how-to-troubleshoot-when-your-floating-pond-fountain-is-not-working-properly) view over the [application](https://www.mindstick.com/articles/12824/calculator-application-in-android). It will never receive focus. The user will probably be in the middle of typing [something else](https://www.mindstick.com/forum/1654/can-anybody-say-my-below-code-is-a-variable-function-or-something-else). The idea is to be as [unobtrusive](https://www.mindstick.com/interview/23012/what-is-unobtrusive-javascript) as possible, while still showing the user the information you want them to see. Two examples are the volume control, and the brief [message saying](https://answers.mindstick.com/qa/50244/how-can-you-fix-the-problem-if-there-is-a-message-saying-the-windows-logon-ui-encountered-a-problem-and-needed-to-close-and-if-the-system-restoring-won-t-work) that your [settings](https://www.mindstick.com/blog/63563/steps-to-change-the-wireless-settings-using-linksys-cloud-account) have been saved.

Basically we are use below code to show toast notification in android.

```
     Toast.makeText(MyActivity.this,                                "My Toast Notification",                                Toast.LENGTH_SHORT).show();
```

Here I am telling you to create [custom notification](https://www.mindstick.com/forum/33810/remote-view-in-android-auto-cancel-custom-notification). You can add buttons, textview, imagview etc in toast layout.

##### Follow below code to show custom views in toast notification.

##### \
1. Create an android project in eclipse or Android studio.

##### \
2. Add two button for show normal toast and custom toast in

##### activity_main.xml file

```
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:tools="http://schemas.android.com/tools"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:orientation="vertical"    android:paddingBottom="@dimen/activity_vertical_margin"    android:paddingLeft="@dimen/activity_horizontal_margin"    android:paddingRight="@dimen/activity_horizontal_margin"    android:paddingTop="@dimen/activity_vertical_margin"    tools:context=".MainActivity" >     <Button        android:id="@+id/btnNormalToast"        android:layout_width="fill_parent"        android:layout_height="wrap_content"        android:layout_marginTop="10sp"        android:text="Show Normal Toast" />     <Button        android:id="@+id/btnCustmToast"        android:layout_width="fill_parent"        android:layout_height="wrap_content"        android:layout_marginTop="10sp"        android:text="Show Custom Toast" /> </LinearLayout>
```

3. Add Create custom layout for show toast notification name as my_custom_layout.[xml file](https://www.mindstick.com/articles/75/how-to-read-and-write-xml-file-through-c-sharp)

```
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:background="#666633"    android:gravity="center"    android:orientation="vertical" >     <ImageView        android:layout_width="60sp"        android:layout_height="60sp"        android:layout_gravity="center"        android:src="@drawable/ic_launcher" />     <TextView        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_gravity="center"        android:text="  Hi am using custom notification  "        android:textColor="#FFFFFF"        android:textSize="17sp" /> </LinearLayout>
```

4. Add following code in MainActivity.class

```
package com.example.toastdemo; import android.os.Bundle;import android.app.Activity;import android.content.Context;import android.view.Gravity;import android.view.LayoutInflater;import android.view.Menu;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;import android.widget.Toast; public class MainActivity extends Activity {     Button btnCustom, btnNormal;      @Override     protected void onCreate(Bundle savedInstanceState) {           super.onCreate(savedInstanceState);           setContentView(R.layout.activity_main);           btnCustom = (Button) findViewById(R.id.btnCustmToast);           btnNormal = (Button) findViewById(R.id.btnNormalToast);           btnNormal.setOnClickListener(new OnClickListener() {                 @Override                public void onClick(View v) {                     // TODO Auto-generated method stub               Toast.makeText(MainActivity.this,                              "Hi am using normal toast notification",                                Toast.LENGTH_SHORT).show();                 }           });           btnCustom.setOnClickListener(new OnClickListener() {                 @Override                public void onClick(View v) {                // create object of toast class        Toast toast = new Toast(MainActivity.this);          // set time out of toast notification             toast.setDuration(Toast.LENGTH_LONG);       // set gravity of toast notification. It will be show in center       // of the screen.            toast.setGravity(Gravity.CENTER, 0, 0);       // create Layout inflater for add layout on view          LayoutInflater inflater = (LayoutInflater) MainActivity.this                   .getSystemService(Context.LAYOUT_INFLATER_SERVICE);       // add layout on views         View view = inflater.inflate(R.layout.my_custom_toast, null);       // add view on toast view         toast.setView(view);       // show toast         toast.show();                 }           });     }      @Override     public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present.           getMenuInflater().inflate(R.menu.main, menu);           return true;     } } 
```

Now run you application

![Create custom toast notification in android](https://www.mindstick.com/blogs/334f2e7c-d354-4a6f-a772-573eb878b57e/images/cf522813-cb93-4ee0-814b-e6847d4dd43e.png)

\
See normal notification

![Create custom toast notification in android](https://www.mindstick.com/blogs/334f2e7c-d354-4a6f-a772-573eb878b57e/images/0b34e0ee-516d-4cc4-ba78-92d20d990b1f.png)\

See custom notification

![Create custom toast notification in android](https://www.mindstick.com/blogs/334f2e7c-d354-4a6f-a772-573eb878b57e/images/ccb3430c-6434-4884-9523-d1742498634c.png)

---

Original Source: https://www.mindstick.com/blog/10925/create-custom-toast-notification-in-android

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
