一个自定义的居中显示的Toast提示对话框,代码如下:
--------------------------------------------------------------------------------------------------------------------------------------
public class ToastShow {
private Context context; // 在此窗口提示信息
private Toast toast = null; // 用于判断是否已有Toast执行
public ToastShow(Context context) {
this.context = context;
}
public void toastShow(String text) {
if (toast == null) {
toast = Toast.makeText(context, text, Toast.LENGTH_SHORT); // 正常执行
} else {
toast.setText(text); // 用于覆盖前面未消失的提示信息
}
toast.setGravity(17, 0, -30);// 居中显示
toast.show();
}
// 取消Toast
public void toastCancel() {
if (null != toast) {
toast.cancel();
}
}
使用的话,先初始化,然后分别调用toastShow 弹出消息, toastCancel()取消提示即可。 详细的就不写给大家了,很简单的。
小奋斗文章
--------------------------------------------------------------------------------------------------------------------------------------