android学习笔记2:toast

来源:互联网 发布:赞美女网络词语 编辑:程序博客网 时间:2024/04/27 05:40

Toast最少显示4秒,连续点击n次,会在n*4秒后才消失,可以定义全局变量来解决此问题。

private Toast toast = null;// 提示框,用来控制所有提示
private TextView textView = null;// 提示框背景

public void showToast(String str) {
if (null == toast) {
toast = new Toast(getContext());
textView = new TextView(getContext());
}
textView.setText(str);
toast.setView(textView);
toast.show();
}


原创粉丝点击