【问题标题】:how to check if the toast have dismissed or not [duplicate]如何检查吐司是否已解除[重复]
【发布时间】:2011-05-06 06:57:04
【问题描述】:

我想检查 toast 是否已关闭,因为用户单击鼠标显示 toast,但可能我用户连续单击,所以我需要检查,我无法使用对话框

【问题讨论】:

    标签: android


    【解决方案1】:
    Toast toast = null;
    if (toast == null || toast.getView().getWindowVisibility() != View.VISIBLE) {
        toast = Toast.makeText(getApplicationContext(),
            "Text", Toast.LENGTH_SHORT);
        toast.show();
    }
    

    在再次显示之前检查 toast 是否可见。

    【讨论】:

    • 显示 toast getWindowVisibility 返回 View.GONE (6.0.1)
    【解决方案2】:
    Toast toast = yourToastCreationCode();
    
    if (null == toast.getView().getWindowToken())
    {
        yeahToastIsInvisible();
    }
    

    【讨论】:

    • noe .. 如果创建了 toast 它将仍然为 null .. 无法检查可见性
    【解决方案3】:

    基于丹尼斯的回答,但对我来说效果更好。

    Toast t;
    t=Toast.makeText(getActivity(), "test", Toast.LENGTH_LONG);
    t.show;
    
    if (t.getView().isShown())
    {
       //visible
    }
    

    【讨论】:

    • isShown 不起作用
    • 根据文档 isShown() “返回此视图及其所有祖先的可见性”所以这不起作用
    猜你喜欢
    • 2020-09-19
    • 2018-09-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-11
    • 2012-02-05
    • 2017-11-17
    相关资源
    最近更新 更多