创建全屏自定义Toast

时间:2012-10-20 17:52:55

标签: android fullscreen toast

我已按照教程重新尝试了自定义Toast:

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

使用这样的布局:

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

但似乎根布局中的fill_parent无效。

你是否知道如何解决这个问题才能获得全屏Toast?

2 个答案:

答案 0 :(得分:20)

在显示Toast:

之前添加此项
toast.setGravity(Gravity.FILL, 0, 0);

答案 1 :(得分:1)

要完全填充其容器大小的水平和垂直面包,您需要使用

在Yoah的回答中提到了

Gravity.FILL

我试过跟随它并且有效。

Toast toast = new Toast(getApplicationContext());
toast.setGravity(Gravity.FILL, 0, 0);
toast.setView(view); //inflated view
toast.setDuration(Toast.LENGTH_LONG);
toast.show();
相关问题