You may have a custom view inflating a custom view and using toast.setView(layout) .
Example:
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();
And your xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/toast_layout_root" android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="fill_parent" android:padding="8dp" android:background="#DAAA" > <ImageView android:src="@drawable/droid" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginRight="8dp" /> <TextView android:id="@+id/text" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textColor="#FFF" /> </LinearLayout>
Additional Information @
http://developer.android.com/guide/topics/ui/notifiers/toasts.html
Edit your, if even part of the code (separately), it shows a toast with a red background and white text. I do not see any problems. But if you need to customize, you can use your own layout and inflate the layout and set the presentation to toast.
Edit:
Your text image
TextView text = (TextView) toast.getView().findViewById(android.R.id.message);
initialized in the if part, otherwise the textview part is not initialized.
Initialize text outside the external if and else code.
Check out this crouton library you might find useful
https://github.com/keyboardsurfer/Crouton
source share