Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Button in custom Android Toast?

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?

like image 786
Sephy Avatar asked Jul 22 '10 12:07

Sephy


People also ask

How do I customize a toast on Android?

If a simple text message isn't enough, you can create a customized layout for your toast notification. To create a custom layout, define a View layout, in XML or in your application code, and pass the root View object to the setView (View) method. Notice that the ID of the LinearLayout element is "toast_layout".

How custom toast view is created?

To create a custom toast view, you need to create a custom layout file in XML and pass the root View object to the setView(View) method. First, retrieve the LayoutInflater with getLayoutInflater() (or getSystemService() ), and then inflate the layout from XML using inflate(int, ViewGroup) .


1 Answers

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.

like image 59
Janusz Avatar answered Sep 22 '22 21:09

Janusz