How can I include a button in a Toast notification?

后端 未结 5 1893
广开言路
广开言路 2020-12-12 23:05

First of all, I know this has been asked before: Button in custom Android Toast?. This is nearly an exact duplicate, but I think that it warrants a new question based on the

相关标签:
5条回答
  • 2020-12-12 23:19

    The Gmail undo bar is't a toast, here is how Google did it

    http://code.google.com/p/romannurik-code/source/browse/misc/undobar/src/com/example/android/undobar/UndoBarController.java

    I guess this answers your question.

    0 讨论(0)
  • 2020-12-12 23:27

    If you want a button in a toast, its better you quit that idea. But you can use dialogs in place of toast. Using dailogs, you will be able to display whatever you want (same function as a toast would do). Also in the dailog, you could set buttons.

    0 讨论(0)
  • 2020-12-12 23:31

    What you're referring to is not a Toast but what Google has dubbed a Snackbar. See the Material Design guidelines.

    You can find several implementations of this on GitHub. Some also go by the name of UndoBar

    Currently, the most extensive, popular, and active one seems to be Snackbar by nispok, which I also happen to be using.

    0 讨论(0)
  • 2020-12-12 23:34

    Gmail on iOS does provide a toast and it is a much better solution than interrupting the user flow with a dialog.

    ![Toast style message in Gmail for iOS][1] [1]: http://i.stack.imgur.com/LWClq.jpg

    If you use this option, make sure the toast is displayed long enough for the user to tap undo if needed. So 5 seconds as opposed to 2.5-3 seconds in a info-only toast.

    The other example cited by CommonsWare is the inline feedback which is shown after a swipe gesture. This is not a toast- but it is also a great way to provide feedback that an action has been performed.

    0 讨论(0)
  • 2020-12-12 23:38

    I have extended the UndoBar mentioned by @Hazem (link) and made it more generic so that it can be used for other actions also. You can have a look here.

    0 讨论(0)
提交回复
热议问题