Toast的显示

/**
 * 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();
	}
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值