Android Toast封装
2015-08-12 00:10
411 查看
package com.whoop.mobile.trace.util; import android.content.Context; import android.content.res.Resources; import android.view.Gravity; import android.widget.Toast; public class ToastUtil { private Context mContext; private Resources mResources; private ToastUtil() { super(); } private ToastUtil(Context context){ this.mContext = context; this.mResources = context.getResources(); } public void showShortToast(String msg) { showToast(mContext, msg, Toast.LENGTH_SHORT); } public void showShortToast(int strRes) { showShortToast(mResources.getString(strRes)); } public void showLongToast(String msg) { showToast(mContext, msg, Toast.LENGTH_LONG); } public void showLongToast(int strRes) { showLongToast(mResources.getString(strRes)); } public void showToast(Context context, String msg, int duration){ showToast(context, msg, duration,Gravity.CENTER); } public void showToast(Context context, String msg, int duration,int gravity){ Toast toast = Toast.makeText(context, msg, duration); toast.setGravity(gravity, 0, 0); toast.show(); } }
相关文章推荐
- 千锋扣丁学堂 如何学习android高级编程
- android官方侧滑菜单DrawerLayout详解
- Android获取数据库sqlite文件方法的命令(亲测无root手机上可行)
- Android Studio中ButterKnife插件的安装与使用
- android 自定义Toast显示风格
- Android控件Editext、TextView属性详解
- android studio 新建module
- Android-报错总结之一:WebView加载本地JS
- Android Studio 工具栏切换卡顿
- 修改Android签名证书keystore的密码、别名alias以及别名密码
- android那些事(一)
- Android技能杂谈——如何优雅的处理控件的点击事件
- android 中如何限制 EditText 最大输入字符数
- Diving Into Android 'M' Doze
- 记Android里的坐标
- Android打包常见错误之Export aborted because fatal lint errors were found
- android中代码形式注册广播接收者
- android中手势识别器的使用
- Android 程序crash后重新启动
- ViewPager