Monday, 7 January 2013

Custom Toast in Android

First Create New Android Project and after that add below xml file in res/layout folder and add below code into your file.


<LinearLayout xmlns:android=""
    android:background="#ffffff" >
    <ImageView android:id="@+id/image"
        android:layout_marginRight="10dp" />

    <TextView android:id="@+id/text"
        android:textColor="#FFF" />

Add below code into your file

LayoutInflater inflater = getLayoutInflater();

View layout = inflater.inflate(R.layout.toast_layout, (ViewGroup) findViewById(;
ImageView image = (ImageView) layout.findViewById(;
TextView text = (TextView) layout.findViewById(;
text.setText("Hello! This is a custom toast!");
Toast toast = new Toast(getApplicationContext());
toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);

Enjoy  :-)

Don’t forget to provide feedback or follow this blog, if you find this blog is useful.

1 comment:

  1. HI Dipak,Please send me android custom pdf viewer source code it will will helpfull for me