安卓常用工具类-ToastUtils【提示工具类】
2017-10-22 11:39
316 查看
该工具类做了优化处理,若A消息正在显示提示,此时B消息进来,会直接改变提示的文字内容。不会等A消息结束再弹出。提高了用户体验~
package com.example.burro.demo.appframework.util; import android.content.Context; import android.os.Handler; import android.widget.Toast; /** * 提示工具类 * Created by burro on 2017/9/23. */ public class ToastUtils { private static Toast mToast; private static Handler mHandler = new Handler(); private static Runnable r = new Runnable() { public void run() { mToast.cancel(); } }; /** * 提示 * * @param mContext * @param text String 内容 */ public static void showToast(Context mContext, String text) { if (!StringUtils.isStrEmpty(text)) { if (mToast != null) mToast.setText(text.trim()); else mToast = Toast.makeText(mContext, text.trim(), Toast.LENGTH_SHORT); mToast.show(); } } public static void showToast(Context mContext, String text, int duration) { if (!StringUtils.isStrEmpty(text)) { mHandler.removeCallbacks(r); if (mToast != null) mToast.setText(text); else mToast = Toast.makeText(mContext, text, Toast.LENGTH_SHORT); mHandler.postDelayed(r, duration); mToast.show(); } } public static void showToast(Context mContext, int resId, int duration) { showToast(mContext, mContext.getResources().getString(resId), duration); } }
相关文章推荐
- 安卓常用工具类-StringUtils【String字符串工具类】
- 【工具类】Android自定义提示框、对话框、加载框
- ToastUtils工具类
- Android提示信息的工具类
- Android ToastUtils,吐司工具类
- [工具类]基于easyui的页面等待提示层,即mask
- ToastUtils工具类
- [工具类]基于easyui的页面等待提示层,即mask
- 【Android工具类】用户输入非法内容时的震动与动画提示——EditTextShakeHelper工具类介绍
- 用户输入非法内容时的震动与动画提示——EditTextShakeHelper工具类介绍
- 【Android工具类】用户输入非法内容时的震动与动画提示——EditTextShakeHelper工具类介绍
- 整理安卓开发工具类列表,有些确实的,就自己整理吧,ToastUtils
- 【Android工具类】用户输入非法内容时的震动与动画提示——EditTextShakeHelper工具类介绍
- ToastUtils工具类
- RecyclerView 的工具类,更方便的实现 Adapter,item 点击事件,更快的实现加载提示,分页加载。
- Android中一些基本的工具类,如ToastUtils,PrefUtils,StreamUtils,MD5Utils...
- 工具类--PopDialogUtils 窗口提示工具类
- BadgeView新提示开源工具类
- Toast工具类,防止多次点击,重复提示
- Swing 中各种提示框的工具类