【问题标题】:Can We identify If a View is a Toast or a Dialog? If Yes then How?我们可以识别视图是 Toast 还是 Dialog 吗?如果是,那么如何?
【发布时间】:2018-10-28 22:49:09
【问题描述】:

我有一个视图实例,我想以编程方式检测视图是来自 Toast 消息还是视图是对话。 Toast 对象内部有一个视图对象。我们还可以设置自定义视图来吐司或对话。 但我没有那个 toast 对象的实例。我只有那个视图对象,我想检测它是否是 toast。

有什么方法可以检测到上述情况。

【问题讨论】:

    标签: android android-layout android-view android-toast


    【解决方案1】:

    如果你有一个视图实例,然后检查如下

    if (view instanceof Dialog){
    
     } else if (view instanceof Toast){
    
    }
    

    【讨论】:

    • 你会得到 cannot inconvertible type: cast View to Toast 错误。
    猜你喜欢
    • 2014-05-15
    • 2013-12-29
    • 2021-08-20
    • 2010-09-19
    • 1970-01-01
    • 1970-01-01
    • 2010-10-26
    • 2012-07-21
    • 2017-12-26
    相关资源
    最近更新 更多