安卓常用工具类-ToastUtils【提示工具类】
来源:互联网 发布:apache压缩包下载 编辑:程序博客网 时间:2024/06/06 19:18
该工具类做了优化处理,若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); }}
阅读全文
0 0
- 安卓常用工具类-ToastUtils【提示工具类】
- ToastUtils工具类
- ToastUtils工具类
- ToastUtils工具类
- 整理安卓开发工具类列表,有些确实的,就自己整理吧,ToastUtils
- 安卓常用工具类
- 安卓常用工具类
- 安卓常用工具类
- 安卓常用工具类
- 安卓常用工具类
- 工具类——吐司ToastUtils封装
- 安卓常用工具类-LogUtils【日志打印工具类】
- 安卓常用工具类-FileUtils【文件相关的工具类】
- 安卓常用工具类-SharePreferenceUtils【偏好存储工具类】
- 安卓常用工具类-SoftKeyboardUtils【软件盘工具类】
- 安卓常用工具类-StringUtils【String字符串工具类】
- 安卓常用工具类-NotifyUtils【通知工具类】
- 安卓常用工具类-CrashHandler【错误日志获取保存工具】
- Task Scheduler
- AlphaGo Zero的伟大与局限—ResNet作者、旷视研究院院长孙剑深度评述
- 一文了解机器学习开发工具
- 掘金3000亿在线教育市场 ‖ 沪江英语、流利说、Master Learner如何用AI影响1400万教师和1.88亿学生
- 一些JAVA代码(单词长度)
- 安卓常用工具类-ToastUtils【提示工具类】
- dedecms相关文档调用方法
- 数据库索引基础知识整理
- tensorflow 笔记(1)
- C++线程池-ThreadPool
- MySQL负载均衡配置
- 唤醒线程是否要持有锁(Signal With Mutex Locked Or Not?)
- java 动态规划最大公共子序列问题
- tcpdump抓包分析利器——wireshark