How can I be notified when a Snackbar has dismissed itself?

前端 未结 12 1538
陌清茗
陌清茗 2020-12-01 00:24

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 loo

12条回答
  •  抹茶落季
    2020-12-01 01:08

    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.addCallback(new Snackbar.Callback() {
    
        @Override
        public void onDismissed(Snackbar snackbar, int event) {
          //see Snackbar.Callback docs for event details
          ...  
        }
    
        @Override
        public void onShown(Snackbar snackbar) {
           ...
        }
      });
    

提交回复
热议问题