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\
You should use a Snackbar
. It is in the latest android support library(at time of answer) and is compatible with older api levels. It is much easier to implement than a Dialog
or custom View
and has the ability to have a button unlike a Toast
.
Android Support Library
from Extras
in the SDK Manager
(revision 22.2.1 or later).build.gradle
add this to the class dependencies: com.android.support:design:22.2.0
.Implement:
Snackbar.make(this.findViewById(android.R.id.content), "Toast Message", Snackbar.LENGTH_LONG)
.setAction("Click here to activate action", onClickListener)
.setActionTextColor(Color.RED)
.show;
And that is it. No github projects and implementation is very similiar to Toast
. I used it in one of my projects and it works great.