我怎样才能得到通知时,小吃吧驳回了自己? [英] How can I be notified when a Snackbar has dismissed itself?

查看:197
本文介绍了我怎样才能得到通知时,小吃吧驳回了自己?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用的小吃店从 com.android.support:design:22.2.0 库。我用它来撤消删除。为了使我的生活更轻松,我要使用户界面看起来像的东西实际上是从数据源中删除,如果是在小吃店撤消按钮没有pressed,实际上是从数据源中执行删除操作。所以,我想知道什么时候小吃吧不再是可见的,所以它的安全删除的项目。

I'm using a Snackbar from the com.android.support:design:22.2.0 library. I'm using it to undo deletions. To make my life easier, I'm going to make the UI look like things are actually deleted from the data source, and if the undo button in the snack bar is not pressed, actually perform the deletions from the data source. So, I want to know when the Snackbar is no longer visible, so it's safe to delete the items.

我可以调用getView()上的小吃吧,但我不知道听众我应该使用。我试过 setOnSystemUiVisibilityChangeListener(),但没有工作,我相信它是只针对系统状态栏。

I can call getView() on the Snackbar, but I'm not sure what listener I should be using. I tried setOnSystemUiVisibilityChangeListener() but that didn't work, I believe it is only for the system status bar.

此外,小吃吧不能扩展,因为它有一个私有的构造函数。

Additionally, Snackbar can not be extended, as it has a private constructor.

推荐答案

谷歌设计库支持小吃吧回调版本23.见的Snackbar文档和<一href="http://developer.android.com/reference/android/support/design/widget/Snackbar.Callback.html">Callback文档。 (显示的时候也是)然后,您将得到通知时,该小吃吧被驳回,也被解雇的类型,如果这是对您有用:

Google design library supports Snackbar callbacks in version 23. See Snackbar docs and Callback docs. You will then get notified when the Snackbar gets dismissed (and also when shown) and also the type of dismissal if this is useful for you:

snackbar.setCallback(new Snackbar.Callback() {

    @Override
    public void onDismissed(Snackbar snackbar, int event) {
      //see Snackbar.Callback docs for event details
      ...  
    }

    @Override
    public void onShown(Snackbar snackbar) {
       ...
    }
  });

这篇关于我怎样才能得到通知时,小吃吧驳回了自己?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆