博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Android弹出Toast工具类总结
阅读量:4591 次
发布时间:2019-06-09

本文共 2576 字,大约阅读时间需要 8 分钟。

 Android弹出Toast工具类总结,包括系统自带的,也包括自定义的。

 

public class ToastUtil {    public ToastUtil() {    }    public static Toast showShortToast(Context context, String text) {        Toast toast = Toast.makeText(context, text, 0);        toast.show();        return toast;    }    public static Toast showShortToastCenter(Context context, String text) {        Toast toast = Toast.makeText(context, text, 0);        toast.setGravity(17, 0, 0);        toast.show();        return toast;    }    public static Toast showShortToast(Context context, @StringRes int textResId) {        Toast toast = Toast.makeText(context, I18nUtil.getString(textResId, new Object[0]), 0);        toast.show();        return toast;    }    public static Toast showLongToast(Context context, String text) {        Toast toast = Toast.makeText(context, text, 1);        toast.show();        return toast;    }    public static Toast showLongToast(Context context, @StringRes int textResId) {        Toast toast = Toast.makeText(context, I18nUtil.getString(textResId, new Object[0]), 1);        toast.show();        return toast;    }    public static Toast showLongToastImage(Context context, @DrawableRes int imgResId) {        Toast toast = new Toast(context);        FrameLayout fl = new FrameLayout(context);        ImageView iv = new ImageView(context);        iv.setImageResource(imgResId);        fl.addView(iv);        toast.setView(fl);        toast.setDuration(1);        toast.show();        return toast;    }    public static Toast showToastWithIcon(Context context, String text, @DrawableRes int img, OnAttachStateChangeListener listener, int duration) {        Toast toast = new Toast(context);        View container = View.inflate(context, layout.view_custom_toast_action_success, (ViewGroup)null);        if(listener != null) {            container.addOnAttachStateChangeListener(listener);        }        TextView tv = (TextView)container.findViewById(id.view_toast_text_img_tv);        ImageView iv = (ImageView)container.findViewById(id.view_toast_text_img_iv);        toast.setGravity(119, 0, 0);        toast.setDuration(duration);        toast.setView(container);        tv.setText(text);        iv.setImageResource(img);        toast.show();        return toast;    }    public static Toast showToastWithIcon(Context context, @StringRes int text, @DrawableRes int img, OnAttachStateChangeListener listener, int duration) {        return showToastWithIcon(context, I18nUtil.getString(text, new Object[0]), img, listener, duration);    }}

 

转载于:https://www.cnblogs.com/hsqdboke/p/10170360.html

你可能感兴趣的文章
sql语句一些简单的用法
查看>>
领域驱动设计之聚合与聚合根实例一
查看>>
selenium中各个模块操作:下拉框、鼠标悬浮连贯、拼图拖拽操作
查看>>
C# 调用Windows图片查看器
查看>>
Excel系列教程(1):如何自动填充单元格
查看>>
jQuery中的冒泡事件和阻止冒泡
查看>>
pythonchallenge闯关 第13题
查看>>
linux上很方便的上传下载文件工具rz和sz使用介绍
查看>>
React之特点及常见用法
查看>>
【WEB前端经验之谈】时间一年半,或沉淀、或从零开始。
查看>>
优云软件助阵GOPS·2017全球运维大会北京站
查看>>
java23中设计模式只责任链模式
查看>>
linux 装mysql的方法和步骤
查看>>
poj3667(线段树区间合并&区间查询)
查看>>
51nod1241(连续上升子序列)
查看>>
SqlSerch 查找不到数据
查看>>
集合相关概念
查看>>
Memcache 统计分析!
查看>>
(Python第四天)字符串
查看>>
个人介绍
查看>>