customer_toast_bg

<?xml version="1.0" encoding="utf-8"?>        

R.layout.customer_toast

?xml version="1.0" encoding="utf-8"?>    

public class CustomerToast {    private static Toast mToast;    private static final String TAG = "CustomerToast";    private static Toast initToast(Context context, CharSequence text, int duration) {        View v = initView(context, text.toString());        Toast toast = new Toast(context.getApplicationContext());        toast.setDuration(duration);        toast.setView(v);        toast.setGravity(Gravity.CENTER, 0, 0);        return toast;    }    public static void show(final Context context, final CharSequence text, final int duration) {        if (Thread.currentThread() == Looper.getMainLooper().getThread()) {            showInUIThread(context, text, duration);        } else {            new Handler(Looper.getMainLooper()).post(new Runnable() {                @Override                public void run() {                    showInUIThread(context, text, duration);                }            });        }    }    private static void showInUIThread(Context context, CharSequence text, int duration) {        if (!TextUtils.isEmpty(text)) {            if (mToast == null) {                LogUtil.d(TAG, "mToast == null");                mToast = initToast(context, text, duration);                mToast.show();            } else {                LogUtil.d(TAG, "mToast != null");                mToast.cancel();                mToast = initToast(context, text, duration);                // View v = initView(context, text.toString());                // mToast.setView(v);                mToast.show();            }        } else {            LogUtil.e(TAG, "text is empty");        }    }    public static void show(Context context, int textId, int duration) {        String text = context.getString(textId);        if (!TextUtils.isEmpty(text)) {            if (mToast == null) {                LogUtil.d(TAG, "mToast == null");                mToast = initToast(context, text, duration);                mToast.show();            } else {                LogUtil.d(TAG, "mToast != null");                mToast = initToast(context, text, duration);                mToast.show();            }        } else {            LogUtil.e(TAG, "text is empty");        }    }    private static View initView(Context context, String text) {        View v = LayoutInflater.from(context).inflate(R.layout.customer_toast, null);        TextView textView = (TextView) v.findViewById(R.id.message);        textView.setText(text);        return v;    }}
public class ToastUtil {    public static void toastNetworkError() {        toastNormal(ASApplication.getInstance(), ASApplication.getInstance().getString(R.string.network_error));    }    public static void toastNormal(Context context, String content) {        CustomerToast.show(context.getApplicationContext(), content, Toast.LENGTH_SHORT);    }    public static void toastLong(Context context, String content) {        CustomerToast.show(context, content, Toast.LENGTH_LONG);    }    public static void toastLongNormal(Context context, String content) {        CustomerToast.show(context, content, Toast.LENGTH_LONG);    }    public static void toastNormal(String content) {        CustomerToast.show(ASApplication.getAppContext(), content, Toast.LENGTH_SHORT);    }    public static void toastNormal(int content) {        CustomerToast.show(ASApplication.getAppContext(), content, Toast.LENGTH_SHORT);    }}

更多相关文章

  1. 代码中设置drawableleft
  2. android 3.0 隐藏 系统标题栏
  3. Android开发中activity切换动画的实现
  4. Android(安卓)学习 笔记_05. 文件下载
  5. Android中直播视频技术探究之—摄像头Camera视频源数据采集解析
  6. 技术博客汇总
  7. android 2.3 wifi (一)
  8. AndRoid Notification的清空和修改
  9. Android中的Chronometer

随机推荐

  1. windowSoftInputMode属性设置值
  2. android布局属性详解
  3. Android(安卓)平铺背景图片
  4. Android(安卓)进程和线程
  5. Android(安卓)SDCard操作(文件读写,容量
  6. android 摄像头图像数据YUV转Bitmap, 再转
  7. 初次在Android上使用OpenCV
  8. android 环境配置
  9. android逆向工程教程
  10. Android(安卓)TextView文字过多时通过滚