Custom Toast Cancel not working

前端 未结 4 1051
南笙
南笙 2021-02-09 20:52

I have seen a number of questions on cancelling toast. None of them is working.

I have a custom Toast. The code for that is all but one line same as http://developer.an

4条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-02-09 21:15

    I suffered from same issue (custom toast queuing up) and found a solution. It worked fine in my case.

    Having custom toast object initially set to null.

    • If this is null, create new custom toast object with "new".

    • As far as you are in same activity, don't "new" to create new object. Instead, use that object. Since setText() won't work in this case, use setView() as you do with your custom toast.

    • With this way show(), cancel(), show(), cancel() worked exactly as I expect. No delay, no queuing.

    Hope this helps.

提交回复
热议问题