I create my own toast mainly because I put it on the grid and need some control over its width. But I really like the light blue halo on the standard toast and would like to bring it back (or at least my custom toast looks a bit like the default toast).
What is a simple / elegant way to achieve this?
I created a custom toast from this layout:
<LinearLayout android:id="@+id/toast_layout_root" android:layout_width="fill_parent" android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal" android:padding="10dp"> <ImageView android:id="@+id/toast_layout_image" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/icon" android:layout_marginRight="10dp"> </ImageView> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/toast_layout_text" android:textColor="#FFF" android:textAppearance="?android:attr/textAppearanceLarge"> </TextView> </LinearLayout>
and refer to it this way (the general approach described in the documentation for Android, as well as several tutorials on the Internet, the only difference is that I work with a grid view, and each toast is placed in accordance with its grid position):
int location[] = new int[2]; view.getLocationOnScreen(location); LayoutInflater inflater = getLayoutInflater(); View toastLayout = inflater.inflate(R.layout.toast_layout,(ViewGroup)findViewById(R.id.toast_layout_root)); TextView textView = (TextView) toastLayout.findViewById(R.id.toast_layout_text); textView.setText("This tile does not contain any valid data."); int toastWidth = cellWidth * 3 / 4; textView.setWidth(toastWidth - 64);
It looks very clean, but completely different from the default toast.
source share