• Android弹出Toast工具类总结


     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);
        }
    }
  • 相关阅读:
    实战:当jquery遇上了json
    验证文本域字符个数的正则表达式
    分布式缓存方案:Memcached初探
    Asp.Net Forms验证(自定义、角色提供程序、单点登录) [转]
    C#3.0扩展方法[转]
    HttpWebRequest调用web服务的代码
    解决User.Identity.IsAuthenticated==false 或User.Identity.Name==string.empty的问题[转]
    微软Asp.net Ajax 1.0的AutoComplete控件的几处修正和增强 [转]
    LINQ体验(5)——LINQ语句之Select/Distinct和Count/Sum/Min/Max/Avg(转)
    c# Linq 的分页[转]
  • 原文地址:https://www.cnblogs.com/hsqdboke/p/10170360.html
Copyright © 2020-2023  润新知