自定义 Toast 想要什么样式就可以写什么样式
activity
View toastView = getLayoutInflater().inflate(R.layout.toast_bg, null);
Toast toast=new Toast(getApplicationContext());
toast.setView(toastView);
TextView tv=(TextView)toastView.findViewById(R.id.tv_toast);
tv.setText("您尚未登录,请先登录");
toast.show();
toast_bg.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="@drawable/toast_bg" >
<TextView
android:id="@+id/tv_toast"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:textColor="#000000" >
</TextView>
</LinearLayout>
toast_bg.xml
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<solid android:color="#ffffff" />
<stroke
android:width="1dp"
android:color="#FFFFFF" />
<padding
android:bottom="6dp"
android:left="6dp"
android:right="6dp"
android:top="6dp" />
<corners android:radius="3dp" />
</shape>
原文地址:http://blog.csdn.net/menglele1314/article/details/46560959