Java tutorial
//package com.java2s; import android.content.Context; import android.view.Gravity; import android.view.LayoutInflater; import android.view.View; import android.widget.Toast; public class Main { /** * Creates a custom {@link Toast} with a custom layout View * * @param context * the context * @param resId * the custom view * @return the created {@link Toast} */ public static Toast makeCustomToast(Context context, int resId) { View view = LayoutInflater.from(context).inflate(resId, null); Toast t = new Toast(context); t.setDuration(Toast.LENGTH_SHORT); t.setView(view); t.setGravity(Gravity.CENTER, 0, 0); return t; } }