工具类--吐司toast

来源:互联网 发布:天正制图软件 编辑:程序博客网 时间:2024/04/27 17:38

经常会使用到toast,于是就剥离成工具类,方便实用

重点代码如下:

private Toast toast = null;
public static void showTextToast(Context context, String msg) {
if (toast == null) {
toast = Toast.makeText(context, msg, Toast.LENGTH_SHORT);
toast .setGravity(Gravity.CENTER, 0, 0);//设置toast显示的位置为屏幕中间,不设置即为默认位置
} else {
toast.setText(msg);
}
toast.show();
}

完。。。

0 0