Android Toast 封装,避免Toast消息覆盖,替换系统Toast最好用的封装
Android Toast 封装,避免Toast消息覆盖,无阻塞,等强大功能
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
|
import android.content.Context; import android.os.Handler; import android.os.Looper; import android.widget.Toast; /** * Toast工具类 * @author WikerYong Email:<a href="#">yw_312@foxmail.com</a> * @version 2012-5-21 下午9:21:01 */ public class ToastUtils { private static Handler handler = new Handler(Looper.getMainLooper()); private static Toast toast = null; private static Object synObj = new Object(); /** * Toast发送消息,默认Toast.LENGTH_SHORT * @author WikerYong Email:<a href="#">yw_312@foxmail.com</a> * @version 2012-5-22 上午11:13:10 * @param act * @param msg */ public static void showMessage(final Context act, final String msg) { showMessage(act, msg, Toast.LENGTH_SHORT); } /** * Toast发送消息,默认Toast.LENGTH_LONG * @author WikerYong Email:<a href="#">yw_312@foxmail.com</a> * @version 2012-5-22 上午11:13:10 * @param act * @param msg */ public static void showMessageLong(final Context act, final String msg) { showMessage(act, msg, Toast.LENGTH_LONG); } /** * Toast发送消息,默认Toast.LENGTH_SHORT * @author WikerYong Email:<a href="#">yw_312@foxmail.com</a> * @version 2012-5-22 上午11:13:35 * @param act * @param msg */ public static void showMessage(final Context act, final int msg) { showMessage(act, msg, Toast.LENGTH_SHORT); } /** * Toast发送消息,默认Toast.LENGTH_LONG * @author WikerYong Email:<a href="#">yw_312@foxmail.com</a> * @version 2012-5-22 上午11:13:35 * @param act * @param msg */ public static void showMessageLong(final Context act, final int msg) { showMessage(act, msg, Toast.LENGTH_LONG); } /** * Toast发送消息 * @author WikerYong Email:<a href="#">yw_312@foxmail.com</a> * @version 2012-5-22 上午11:14:09 * @param act * @param msg * @param len */ public static void showMessage(final Context act, final int msg, final int len) { new Thread(new Runnable() { public void run() { handler.post(new Runnable() { @Override public void run() { synchronized (synObj) { if (toast != null) { toast.cancel(); toast.setText(msg); toast.setDuration(len); } else { toast = Toast.makeText(act, msg, len); } toast.show(); } } }); } }).start(); } /** * Toast发送消息 * @author WikerYong Email:<a href="#">yw_312@foxmail.com</a> * @version 2012-5-22 上午11:14:27 * @param act * @param msg * @param len */ public static void showMessage(final Context act, final String msg, final int len) { new Thread(new Runnable() { public void run() { handler.post(new Runnable() { @Override public void run() { synchronized (synObj) { if (toast != null) { toast.cancel(); toast.setText(msg); toast.setDuration(len); } else { toast = Toast.makeText(act, msg, len); } toast.show(); } } }); } }).start(); } /** * 关闭当前Toast * @author WikerYong Email:<a href="#">yw_312@foxmail.com</a> * @version 2012-5-22 上午11:14:45 */ public static void cancelCurrentToast() { if (toast != null) { toast.cancel(); } } } |
Android Toast 封装,避免Toast消息覆盖,替换系统Toast最好用的封装的更多相关文章
- 【Android代码片段之六】Toast工具类(实现带图片的Toast消息提示)
转载请注明出处,原文网址:http://blog.csdn.net/m_changgong/article/details/6841266 作者:张燕广 实现的Toast工具类ToastUtil封装 ...
- Android:谈一谈安卓应用中的Toast情节(基础)
前言 Toast,这个曾经也是现在正在迷倒万千软件开发者尤其是android开发者的小美女,向来不乏在各个明星应用中频繁登场.Toast是神马~听说是一种吐司面包,能吃吗?如果手机屏幕是巧克力做的,我 ...
- 第三部分:Android 应用程序接口指南---第二节:UI---第八章 Toast通知
第8章 Toast通知 Toast通知是在窗口前面弹出的信息.它只占有信息所需要的空间量,并且用户当前的activity仍然是可见的.可互动的.这种通知自动地淡入和淡出,它不接受交互事件.他相当于一种 ...
- Android_(消息提示)多种使用Toast的消息提示
Toast是一种提供给用户简介信息的视图,可以创建和显示消息,该视图以浮于应用程序之上的形式呈现给用户.因为它并不获得焦点,即使用户正在输入什么也不会受到影响. Toast目标是尽可能以不显眼的方式, ...
- Android开发之接收系统广播消息
BroadcastReceiver除了接收用户所发送的广播消息之外.另一个重要的用途:接收系统广播. 假设应用须要在系统特定时刻运行某些操作,就能够通过监听系统广播来实现.Android的大量系统事件 ...
- Android——AutoCompleteTextView、Spinner和消息提示
layout文件: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:an ...
- Android基础------高级ul:消息提示
前言:Android消息提示笔记,刚刚接触Android 1.静态方法Toast 直接调用静态方法 //消息提示(context,"内容",固定时间) Toast.makeText ...
- Android中利用Handler实现消息的分发机制(三)
在第二篇文章<Android中利用Handler实现消息的分发机制(一)>中,我们讲到主线程的Looper是Android系统在启动App的时候,已经帮我们创建好了,而假设在子线程中须要去 ...
- Android学习系列(7)--App消息通知机制
有人说,程序员很安静,但我不完全同意,程序员的聒噪,是藏在代码后面,是藏在程序后面.这篇文章是Android开发人员的必备知识,是我特别为大家整理和总结的,不求完美,但是有用. 1.消息推送机制 ...
随机推荐
- 教你写一个Android可快速复用的小键盘输入控件
引子 在Android项目开发中特别是一些稍大型的项目,面对需求文档的时候你经常会发现很多地方用到了同样的组件,但是又略有不同.比如这个: 右边是一个小键盘输入板,左边当焦点不同的时候分别用右边的小键 ...
- http技术交流提纲
http技术交流提纲地址:http://lazio10000.github.io/tech/http/#/bored
- vitualbox 主机与虚拟机能相互访问的设置
1. 桥接网卡 2. 界面名称:802.11n USB Wireless Lan Card 3. 混杂模式:全部允许 4. 接入网线打勾 5. 确定
- 解决SourceGrid在某些系统上无法用鼠标滚轮滚动的问题
4.40版源码,找到SourceGrid/SourceGrid/Common/CustomScrollControl.cs 这个文件 定位 CustomScrollWheel() 方法,把if条件判断 ...
- WCF 入门 (18)
前言 感冒了呀...but 不忌油炸,不忌辛辣,o(∩_∩)o . 第18集 WCF服务应该抛出fault 异常 Throwing fault exceptions from a WCF servic ...
- 第三十三课:jQuery Deferred详解1
之前我们讲了Mochikit Deferred,JSDeferred,现在讲jQuery Deferred.首先,我们先来讲下他们的区别: 在保存回调函数时,Mochikit Deferred(doj ...
- TRUNC函数,ORA-01898 精度说明符过多
TRUNC(SYSDATE)即可默认当前日期(年月日),TRUNC(SYSDATE,'yyyy-mm-dd'),精度说明符过多
- shell expr的用法
root@tcx4440-03:~# var=$var+1root@tcx4440-03:~# echo $var3+1 要想达到预期结果,用下列三种方法: (1)let "var+=1&q ...
- POJ 1625 Censored!
辣鸡OI毁我青春 Description The alphabet of Freeland consists of exactly N letters. Each sentence of Freela ...
- groovy-运算符
算术和条件运算符 Groovy支”!”操作符,例如: 1 def expression = false 2 assert !expression 基于集合的运算符: Spread Operator ( ...