Android在非UI线程中显示Toast
来源:互联网 发布:flash player mac下载 编辑:程序博客网 时间:2024/05/23 18:14
public class MyToast{/**UI线程中使用,千万别在非UI中使用*/ public static void show(Context context, CharSequence text, int duration) {Toast toast = Toast.makeText(context, text, duration);toast.setGravity(Gravity.CENTER,0,0);toast.show(); }/** * 在非UI线程中,这个方法可以将Toast显示在UI线程 * 原理,追加toast在消息队列中 * 千万别在UI线程中使用 * */ public static void showOnUIThreadx(final Context context,final CharSequence text,final int duration) { Handler handler = new Handler(Looper.getMainLooper()); handler.post(new Runnable() { @Override public void run() { Toast toast = Toast.makeText(context, text, duration); toast.setGravity(Gravity.CENTER,0,0); toast.show(); } }); }/** * 在非UI线程中,这个方法可以将Toast显示在UI线程 * 原理,追加toast在消息队列中 * 千万别在UI线程中使用 * */ public static void showOnUIThread2(final Context context,final CharSequence text,final int duration) { Looper.prepare(); Toast toast = Toast.makeText(context, text, duration);toast.setGravity(Gravity.CENTER,0,0);toast.show();Looper.loop(); } }
参考来自:http://blog.csdn.net/xiaanming/article/details/8904645
0 0
- Android在非UI线程中显示Toast
- Android在非UI线程中显示Toast
- Android在非UI线程中显示Toast
- Android在非UI线程中显示Toast
- Android在非UI线程中显示Toast
- Android在非UI线程中显示Toast
- Android在非UI线程中显示Toast
- Android在非UI线程中显示Toast
- 在非UI线程中显示Toast
- 非UI线程中显示Toast
- 在非UI线程中使用Toast
- 非UI线程中Toast
- Toast在非UI主线程的其他线程中显示报错
- 非UI线程中显示Alertdialog控件或Toast
- Android在所有代码中使用Toast,包括非UI线程
- android非UI线程调用Toast
- Android Toast工具类 解决Toast重复显示,Toast一直显示,在线程中可用
- Android Activity的setTitle,AlertDialog,Toast操作是否都必须在非主UI线程中操作呢?
- Hibernate Validator验证注解说明
- 自定义PreferenceFragment,去掉padding(默认)
- IAR7 Warning: _vector_table symbol not found.
- 渲染世界的OPENGL<14>纹理进阶-多重纹理
- SpringMVC注解@RequestParam全面解析
- Android在非UI线程中显示Toast
- Java实现基于Redis的分布式锁
- 终端 伪终端 控制终端
- android 本地推送之 同时推送
- 源代码审计
- UIPickerView控件中自定义显示的字体大小及样式
- 学者:人民币国际化 高房价拐点来了
- Android 之工具aidl
- ios ld: framework not found Bolts for architecture x86_64