Customising Toast Notifications in Android – Updated

UPDATE: I’ve come across the original documentation here and updated my code snippets as suggested in their doco.

I have also found that interactive controls like buttons don’t seem to work. If anyone has found a way to get it to work let me know, but I guess that if you need to interact with it, an Activity would be a better choice.

Toast notifications are a good way to notify the user about different actions without making them have to click OK buttons, primarily for messages that aren’t absolutely critical.

You can create a standard Toast notification using the following:-

however if you want the notification to be any more complex than an image and line of text you have to create a custom view for it.

First we need to create the new layout. In this case we want a layout with a larger (and static) title with the text below being the one that is set dynamically. The following goes in the layout directory as toast_layout.xml:-

and the shape that defines the borders so it looks just like the generic toast notification. The following goes in an xml file in the drawable directory as toast_shape.xml:-

Set the new layout as the view and set the text field

Your toast notification should now show a title above the text you specified.