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.