Android dialog,toast,snackbar小节
来源:互联网 发布:win7网络共享怎么设置 编辑:程序博客网 时间:2024/05/16 19:08
Dialog
dialog尽量使用 android.support.v7.app.AlertDialog 包下的,外形更符合现在的审美观。
Toast
为了避免弹出多个toast,可以采用下面的工具类
public class ToastUtil { private static Context context; private static Toast toast = null; private static String oldMsg; private static long oneTime = 0; private static long twoTime = 0; public static Context getContext() { return context; } /** * Application中初始化 * public class App extends Application { * * @param context * @Override public void onCreate() { * super.onCreate(); * ToastUtil.setContext(this); * } * } */ public static void setContext(Context context) { ToastUtil.context = context; } /** * 使吐司只更新内容和时间,而不再是重新弹出 * * @param text 内容 */ public static void toast(String text) { if (toast == null) { toast = Toast.makeText(context, text, Toast.LENGTH_SHORT); toast.show(); oneTime = System.currentTimeMillis(); } else { twoTime = System.currentTimeMillis(); if (text.equals(oldMsg)) { if (twoTime - oneTime > Toast.LENGTH_SHORT) { toast.show(); } } else { oldMsg = text; toast.setText(text); toast.show(); } } oneTime = twoTime; }}
Snackbar
使用时先添加 com.android.support:design 库
默认底部弹出,在有底部导航栏的手机上会和导航栏重合,解决方法是把第一个view参数设为:
View view = ((ViewGroup) findViewById(android.R.id.content)).getChildAt(0);
阅读全文
0 0
- Android dialog,toast,snackbar小节
- Android提醒:Dialog,Toast,Snackbar
- Android弹框使用:Dialog&Toast&Snackbar
- Android 信息提示Dialog、Toast和Snackbar
- Android Dialog、Toast和Snackbar详解
- Android提醒技巧,Dialog、Toast和Snackbar
- Android提醒,Dialog、Toast和Snackbar。
- Android中Dialog、Snackbar、Toast使用区别?
- Android中Dialog、Toast和Snackbar使用场景以及技巧
- Android提醒微技巧Dialog、Toast和Snackbar
- Android提醒技巧,Dialog、Toast和Snackbar的使用区别
- Android提醒微技巧,Dialog、Toast和Snackbar
- Android微技巧之Dialog,Toast,Snackbar提醒
- Android开发之————Toast、Dialog、SnackBar
- Android提醒微技巧Dialog、Toast和Snackbar
- Android的各种通知Notification、Dialog、Toast、Snackbar
- Android Toast与Snackbar
- Android Toast与Snackbar
- java中从键盘输入的三种方法
- 关于这样的错误 libcpmtd.lib(string.obj) : error LNK2005: "public: void __thiscall
- Crontab使用
- MYSQL数据文件--.frm文件(只有.frm文件时的表结构恢复)
- 尝试解析js面试题(一)
- Android dialog,toast,snackbar小节
- 数据库方面面试总结
- Spring boot (Hello World 级别)
- java json编程-1
- Python 实例方法 类方法 静态方法 (instance method, class method, static method )
- iOS开发中的Assets.xcassets和Assets.car
- 页面引入JS文件IE6报错 XX函数未定义 对象为空
- Java基础
- **LeetCode 70. Climbing Stairs