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
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.