Android Toast提示封装实例代码
时间:2021-07-16 10:41:54|栏目:Android代码|点击: 次
Android Toast提示封装
Android中经常用到Toast提示,项目中很多Toast提示,写很长的一行,简单的封装一下,将Toast方法提出来,很方便使用:
实例代码:
/** * 提示字符串 * short Toast * @param context * @param text * by Hankkin at:2015-10-07 21:14:43 */ public static void showToast(Context context, String text) { Toast toast = Toast.makeText(context,text,Toast.LENGTH_SHORT); toast.setGravity(Gravity.CENTER,0,0); toast.show(); } /** * 提示字符串 * short Toast * @param context * @param text * by Hankkin at:2015-10-07 21:14:43 */ public static void showLToast(Context context, String text) { Toast toast = Toast.makeText(context, text, Toast.LENGTH_LONG); toast.setGravity(Gravity.CENTER, 0, 0); toast.show(); } /** * 提示根据ResId关联字符串 * short Toast * @param context * @param resId * by Hankkin at:2015-10-07 21:14:43 */ public static void showToast(Context context, int resId) { Toast toast = Toast.makeText(context, resId, Toast.LENGTH_SHORT); toast.setGravity(Gravity.CENTER, 0, 0); toast.show(); } /** * 提示根据ResId关联字符串 * 时常long Toast * @param context * @param resId * by Hankkin at:2015-10-07 21:14:43 */ public static void showLToast(Context context, int resId) { Toast toast = Toast.makeText(context, resId, Toast.LENGTH_LONG);; toast.setGravity(Gravity.CENTER, 0, 0); toast.
感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!
上一篇:android PopupWindow点击外部和返回键消失的解决方法
栏 目:Android代码
下一篇:Android把商品添加到购物车的动画效果(贝塞尔曲线)
本文地址:http://www.codeinn.net/misctech/157807.html