我最近在本教程之后尝试了自定义 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 之前添加以下内容:
toast.setGravity(Gravity.FILL, 0, 0);
要完全填充吐司的水平和垂直大小的容器,您需要使用
Gravity.FILL正如Yoah的回答中提到的。
我尝试跟随,它奏效了。
Toast toast = new Toast(getApplicationContext());
toast.setGravity(Gravity.FILL, 0, 0);
toast.setView(view); //inflated view
toast.setDuration(Toast.LENGTH_LONG);
toast.show();