Snackbar stack will always show only the last snackbar

后端 未结 2 979
名媛妹妹
名媛妹妹 2021-01-26 02:48

The Snackbar.make(...).show() will only show the last snackbar unlike toast the other snackbars are gone.

for(int i = 1;i < 11;i++) {  
   Snackb         


        
2条回答
  •  鱼传尺愫
    2021-01-26 03:25

    I implemented now my own queue:

    protected ArrayList mSnackbarList = new ArrayList<>();
    
    protected Snackbar.Callback mCallback = new Snackbar.Callback() {
        @Override
        public void onDismissed(Snackbar snackbar, int event) {
            mSnackbarList.remove(snackbar);
            if (mSnackbarList.size() > 0)
               displaySnackbar(mSnackbarList.get(0));
        }
    };
    
    public void addQueue(Snackbar snackbar){
        setLayoutParams(snackbar);
        snackbar.setCallback(mCallback);
        boolean first = mSnackbarList.size() == 0;
        mSnackbarList.add(snackbar);
        if(first)
            displaySnackbar(snackbar);
    }
    
    public void displaySnackbar(Snackbar snackbar){
        snackbar.show();
    }
    

提交回复
热议问题