带图片的吐司窗体
快速toast 让其在主线程进行
/**
* //带图片的吐司窗体
*
* @param context 上下文
* @param message 吐司内容
* @param imageId 图片ID
*/
public static void ToastWithImage(final Context context, final Object message, int imageId) {
Toast toast = Toast.makeText(context.getApplicationContext(), "" + message, Toast.LENGTH_SHORT);
toast.setGravity(Gravity.CENTER, 0, 0);
LinearLayout toastView = (LinearLayout) toast.getView();
if (imageId != 0) {
ImageView imageCodeProject = new ImageView(context.getApplicationContext());
imageCodeProject.setImageResource(imageId);
toastView.addView(imageCodeProject, 0);
toast.show();
}
if (imageId == 0) {
toast.show();
}
}
/**
* 快速快速toast 让其在主线程进行
*
* @param mContext
* @param msg
*/
public static void showToast(final Context mContext, final Object msg) {
if (handler == null) {
handler = new Handler(Looper.getMainLooper());
}
handler.post(new Runnable() {
@Override
public void run() {
if (mToast == null) {
mToast = new SoftReference<Toast>(Toast.makeText(mContext, "", Toast.LENGTH_SHORT));
} else {
if (mToast.get() == null) {
mToast = new SoftReference<Toast>(Toast.makeText(mContext, "", Toast.LENGTH_SHORT));
} else {
mToast.get().setText("" + msg);
mToast.get().show();
}
}
}
});
}