/**
* Toast可以指定显示的位置,还可以设置显示的View
*/
public class ToastUtil {
// 默认(短)
public static void defToast(String str, Context context) {
Toast.makeText(context, str, 0).show();
}
// 默认(长)
public static void defLongToast(String str, Context context) {
Toast.makeText(context, str, 1).show();
}
// 中间(短)
public static void centerToast(String str, Context context) {
Toast toast = Toast.makeText(context, str, 0);
toast.setGravity(Gravity.CENTER, 0, 0);
toast.show();
}
// 中间(长)
public static void centerLongToast(String str, Context context) {
Toast toast = Toast.makeText(context, str, 1);
toast.setGravity(Gravity.CENTER, 0, 0);
toast.show();
}
// 顶部(短)
public static void topToast(String str, Context context) {
Toast toast = Toast.makeText(context, str, 0);
toast.setGravity(Gravity.TOP, 0, 0);
toast.show();
}
// 顶部(长)
public static void topLongToast(String str, Context context) {
Toast toast = Toast.makeText(context, str, 1);
toast.setGravity(Gravity.TOP, 0, 0);
toast.show();
}
// 底部(短)
public static void bottomToast(String str, Context context) {
Toast toast = Toast.makeText(context, str, 0);
toast.setGravity(Gravity.BOTTOM, 0, 0);
toast.show();
}
// 底部(长)
public static void bottomLongToast(String str, Context context) {
Toast toast = Toast.makeText(context, str, 1);
toast.setGravity(Gravity.BOTTOM, 0, 0);
toast.show();
}
public static void viewToast(View view, String str, Context context) {
Toast toast = Toast.makeText(context, str, 0);
toast.setView(view);
toast.show();
}
}
Toast的显示
最新推荐文章于 2024-05-13 02:07:05 发布