Toast工具,解决连续弹出toast以及toast不能全屏的问题

来源:互联网 发布:淘宝卖视频教程 编辑:程序博客网 时间:2024/05/07 05:00
public class ToastUtil {    private static final String TAG = ToastUtil.class.getSimpleName();    private ToastUtil() {}    private static Toast mToast = null;    public static final void showToast(Context context, String content) {        LayoutInflater inflater =                (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);        View view = inflater.inflate(R.layout.toast, null);        TextView textview = (TextView) view.findViewById(R.id.toast_content);        if (!TextUtils.isEmpty(content)) {            textview.setText(content);        }        if (mToast == null) {            mToast = new Toast(context);            mToast.setGravity(Gravity.FILL_HORIZONTAL | Gravity.TOP, 0, 0);            mToast.setDuration(Toast.LENGTH_SHORT);        }        mToast.setView(view);        mToast.show();    }}



设置这句

mToast.setGravity(Gravity.FILL_HORIZONTAL | Gravity.TOP, 0, 0);

就可以全屏了。

0 0