如何等待Snackbar?我想知道什么时候关闭

时间:2016-01-03 15:46:45

标签: android snackbar

我希望在Snackbar关闭时获得通知。在一项活动中,我使用了Snackbar,然后我调用了另一项活动,我希望显示Snackbar,并且当它已经关闭时想要startActivity(NextActivity)。我该怎么办呢?

3 个答案:

答案 0 :(得分:8)

Snackbar.make(view, "Some text", Snackbar.LENGTH_SHORT)
            .setCallback(new Snackbar.Callback() {
                @Override
                public void onDismissed(Snackbar snackbar, int event) {
                    super.onDismissed(snackbar, event);

                    startActivity(this, NextActivity.class);
                }
            }).show();

答案 1 :(得分:1)

定义一个动作

void Remove(char *code){

      for (int i = 0; i < _curSize; i++){
          if (strcmp(code, products[i]->getCode()) == 0){
              delete products[i]; // delete product if found
              products[i] = NULL; // reset a pointer
              products[i] = new Product(); // create new 'default' product 
              products[i] = products[_curSize-1]; // copy product at last index at place of deleted product
             // delete products[_curSize-1]; // if this command gets exe, program crashes. 
              products[_curSize-1] = NULL; //
              _curSize -= 1;
              return;
          }
        }

按如下方式定义onClickListenet:

.setAction("Go To Next Activity", mOnClickListener);

More Info Here

答案 2 :(得分:0)

我来晚了,但我希望它对您有用

Scaffold.of(thisContext).showSnackBar(snackBar).closed.then((value){
   print('snackbar closed');
});