Android 自定义toast 宽高大小 背景图片
RelativeLayout layout = (RelativeLayout) getLayoutInflater().inflate(R.layout.layout_custom_toast,null);
((TextView) layout.findViewById(R.id.tvCheckoutWay)).setText("11111");
((TextView) layout.findViewById(R.id.tvPercent)).setText("22222");
Toast toast = new Toast(getApplicationContext());
toast.setDuration(Toast.LENGTH_SHORT);
toast.setGravity(Gravity.CENTER_VERTICAL | Gravity.BOTTOM, 0,(int)getResources().getDimension(R.dimen.spacing_4));
toast.setView(layout);//setting the view of custom toast layout
toast.show();
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<LinearLayout
style="@style/style_base"
android:layout_width="200dp"
android:layout_height="48dp"
android:background="@drawable/bg_toast_data"
android:gravity="center"
>
<TextView
android:id="@+id/tvCheckoutWay"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:text="AAAA" />
<TextView
android:id="@+id/tvPercent"
android:layout_width="wrap_content"
android:layout_height="wrap_content" android:gravity="center"
android:text="{100%}"
android:textColor="@color/green_deep"
android:textSize="@dimen/text_size_menu" />
</LinearLayout>
</RelativeLayout>
图片
android 自定义toast width height 背景图片
原文地址:http://blog.csdn.net/zabio/article/details/43488411