您的位置:首页 > 其它

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

2014-04-23 14:17 253 查看
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);


就可以全屏了。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐