Skip to content

Instantly share code, notes, and snippets.

@ayushhgoyal
Created February 16, 2013 07:07
Show Gist options
  • Save ayushhgoyal/4965905 to your computer and use it in GitHub Desktop.
Save ayushhgoyal/4965905 to your computer and use it in GitHub Desktop.
This code snippet can be used to create a custom toast.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/toast_layout_root"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FFFFFF"
android:orientation="horizontal"
android:padding="8dp" >
<TextView
android:id="@+id/test"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" YO Y O"
android:textColor="#000000" />
</LinearLayout>
LayoutInflater inflater = getLayoutInflater();
View layout = inflater.inflate(R.layout.custom_toast_example,
(ViewGroup) findViewById(R.id.toast_layout_root));
TextView text = (TextView) layout.findViewById(R.id.test);
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();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment