A toast provides simple feedback about an operation in a small popup.
LayoutInflater inflater = getLayoutInflater(); View layout = inflater.inflate(R.layout.custom_toast, (ViewGroup) findViewById(R.id.toast_layout_root)); TextView text = (TextView) layout.findViewById(R.id.text); text.setText("This is a custom toast"); Toast toast = new Toast(getApplicationContext()); toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0); toast.setDuration(Toast.LENGTH_LONG); toast.setView(layout); toast.show();Note: Do not use the public constructor for a Toast unless you are going to define the layout with
setView(View)
. If you do not have a custom layout to use, you must use
makeText(Context, int, int)
to create the Toast.