Button in custom Android Toast?

Sephy picture Sephy · Jul 22, 2010 · Viewed 30k times · Source

Is it possible to have a button in a Toast?

In theory, yes because you can build a custom Toast from a layout in XML, but I tried to put a button in it and couldn't get it to register the click. Did anyone manage to do something like that?

Answer

Janusz picture Janusz · Jul 22, 2010

A toast can not be clicked. It is not possible to capture a click inside a toast message. You will need to build a dialog for that. Look at Creating Dialogs for more info.

The API on the Toast class state that a toast will never receive the focus and because a toast is not a view there is no onClick message. I would assume that therefore childs of a Toast can not be clicked as well.