package com.hxsmart.intelligentizepos.util;
import android.content.Context;
import android.os.Looper;
import android.view.Gravity;
import android.widget.Toast;
import com.hxsmart.intelligentizepos.application.IntelligentizeApplication;
/**
* Toast Util Class
* Created by llbt on 2016/3/31.
*/
public class ToastUtil {
public static void show(Object toastText) {
Toast toast = Toast.makeText(IntelligentizeApplication.getInstance(), toastText != null?toastText.toString():"", Toast.LENGTH_SHORT);
toast.setGravity(Gravity.CENTER, 0, 0);
toast.show();
}
//常规Toast
public static void toast(Context mContext, String str) {
try {
Toast toast = Toast.makeText(mContext, str, Toast.LENGTH_SHORT);
toast.setGravity(Gravity.CENTER, 0, 0);
toast.show();
} catch (Exception e) {
e.printStackTrace();
}
}
//子线程Toast
public static void toastThread(Context mContext, String str) {
try {
Looper.prepare();
Toast toast = Toast.makeText(mContext, str, Toast.LENGTH_SHORT);
toast.setGravity(Gravity.CENTER, 0, 0);
toast.show();
Looper.loop();
} catch (Exception e) {
e.printStackTrace();
}
}
}
工具类:ToastUtil
最新推荐文章于 2025-05-20 01:30:45 发布
本文介绍了一个名为ToastUtil的工具类,该类提供了一种在Android应用中展示Toast消息的方法。文章详细解释了如何使用此工具类显示短时提示信息,并提供了在主线程及子线程中使用Toast的方法。
9502

被折叠的 条评论
为什么被折叠?



