Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating a fullscreen custom Toast

I have recentrly tried a custom Toast following the tutorial:

http://developer.android.com/guide/topics/ui/notifiers/toasts.html#CustomToastView

With such a Layout:

<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>

But it seems that the fill_parent in the root layout has no effect.

Do you have an idea on how I can fix this in order to get fullscreen Toast?

like image 653
Waza_Be Avatar asked Oct 20 '12 17:10

Waza_Be


People also ask

Can we set a custom layout for a Toast?

If a simple text message isn't enough, you can create a customized layout for your toast notification. To create a custom layout, define a View layout, in XML or in your application code, and pass the root View object to the setView (View) method. Notice that the ID of the LinearLayout element is "toast_layout".


1 Answers

Add this before you show the Toast:

toast.setGravity(Gravity.FILL, 0, 0);
like image 108
yoah Avatar answered Oct 07 '22 06:10

yoah