- Create your own layout for the Toast. Add it to the res/layout directory ( file - customizedtoast.xml).
- Create a new LayourInflater, then call the inflate() method passing the Layout of the custom Toast and the root id (id of the linearLayour in our case) .
- Create new Toast and pass the root of the layout to the setView() method of the Toast. Call the show() method.
LayoutInflater li = getLayoutInflater(); View layout = li.inflate(R.layout.customizedtoast, (ViewGroup) findViewById(R.id.customToastLayout));
Toast toast = new Toast(getApplicationContext()); toast.setDuration(Toast.LENGTH_SHORT); toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0); toast.setView(layout); toast.show();
Example:

Complete code :
main.java
package com.blog.customizedtoastnotification;
import android.app.Activity;
import android.os.Bundle;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.Toast;
public class main extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button btn = (Button) findViewById(R.id.button1);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
LayoutInflater li = getLayoutInflater();
View layout = li.inflate(R.layout.customizedtoast,
(ViewGroup) findViewById(R.id.customToastLayout));
Toast toast = new Toast(getApplicationContext());
toast.setDuration(Toast.LENGTH_SHORT);
toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
toast.setView(layout);
toast.show();
}
});
}
}
main.xml