关于我们

质量为本、客户为根、勇于拼搏、务实创新

< 返回新闻公共列表

Toast工具类

发布时间:2023-06-28 12:00:37
import com.eyeguard.app.R; import android.content.Context; import android.view.LayoutInflater; import android.view.View; import android.widget.TextView; import android.widget.Toast; /** * 主要功能: 自定义Toast提示框 */ public class AppToastMgr { //对话框时长号(毫秒) private static int duration = 200; //自定义toast对象 private static Toast toast; /** * 自定义Toast调用 * @param context 上下文 * @param message 显示文本 * @return void */ public static void shortToast(final Context context, final String message) { if (null == toast) { toast = new Toast(context); toast.setDuration(Toast.LENGTH_SHORT); View view = ((LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.sys_show_toast, null); TextView textView = (TextView) view.findViewById(R.id.sys_show_toast_txt); textView.setText(message); toast.setView(view); toast.show(); } else { TextView textView = (TextView) toast.getView().findViewById(R.id.sys_show_toast_txt); textView.setText(message); toast.show(); } } /** * 自定义Toast调用 * @param context 上下文 * @param message 显示文本 * @return void */ public static void longToast(final Context context, final String message) { if (null == toast) { toast = new Toast(context); toast.setDuration(Toast.LENGTH_LONG); View view = ((LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.sys_show_toast, null); TextView textView = (TextView) view.findViewById(R.id.sys_show_toast_txt); textView.setText(message); toast.setView(view); toast.show(); } else { TextView textView = (TextView) toast.getView().findViewById(R.id.sys_show_toast_txt); textView.setText(message); toast.show(); } } /** * 取消显示Toast * * create by fuxiaosong */ public static void cancelToast() { if (null != toast) { toast.cancel(); } } /** * 默认Toast调用 * @param context 上下文 * @param message 显示文本 */ public static void Toast(final Context context, final String message) { Toast.makeText(context, message, duration).show(); } } 这里是用到的布局文件,一并贴出来 最后附上所有工具类的下载链接: http://download.csdn.net/detail/u014727709/9697759 欢迎start,欢迎评论,欢迎指正

/template/Home/leiyu/PC/Static