Custom Toast

Intro

Toasts are the preferred Android mechanism to deliver short messages to users. But, they tend to be kind of boring. So, why not make them more exciting? Let’s build a custom toast and make it pop!

Custom Toast

Custom Layout

First thing we’ll need is a custom layout for amazing toast. Let’s start off with something simple, a TextView and an ImageView:

Custom Toast

Awesome, we’ve defined our Toast’s layout. Time to use it.

First thing we’ll need to do is inflate it and initialize its views:

Next, we’ll create a new toast and add our custom view to it:

We can customize it even further: to make things interesting, we can also define the Toast’s gravity – to control where it appears on the screen:

 

And we’re done, simple as that! This is what the final thing looks like:

And just call it with:

 

Get the full source code here.

Share this on:

5 thoughts on “Custom Toast”

  1. C3QCEP This blog is obviously educating and amusing. I have picked a lot of interesting tips out of it. I ad love to visit it again soon. Thanks a bunch!

  2. Pingback: Google

Leave a Reply

Your email address will not be published.