Read More

Changing Toast Display

In this blog, we will learn about changing Toast Display in your android application.

We all know displaying Toasts in your android application is quite a useful and powerful way of improving your application’s user experience.

But, while using toast, we usually assume that the view cannot be changed and the view provided or displayed is the only way the toast will appear in our application or we try to use some library project to display colorful toasts.

Changing the look and feel of a toast is super easy and is not that much of code as we think or see in library projects.

So, without wasting any time further, let’s see what we need to do.

APPROACH :

  1. You need to create an instance of the Toast class through Toast.makeText() function.
  2. If you need to change the position of the Toast on the Screen then you need to set the gravity by using setGravity() function.
  3. If you need to change the background of the Toast then you need to use getView().setBackground() function.
  4. If You need to change the color of the view created then you need to use getView().getBackground().setColorFilter() function.
  5. If you need to add some icon along with the message in the toast view then you need to first get an instance of the TextView in the toast using getView().findViewById(android.R.id.message) and then use setCompoundDrawablesWithIntrinsicBounds() function.

With these changes, you can change almost all the elements of the Toast as per your use case.

Let’s now look at the code you need to do.

CODE :

And with these changes you have changed the whole Toast Display as per your use.

Keep coding and Keep Sharing 🙂

 

 

. . .

Comment

Add Your Comment

Be the first to comment.

css.php
Hire Us!
Brief us about your requirements and we'll get back to you.
Woo! Hooy!
We have just recieved your project brief and our expert will contact you shortly.
Send Again
Close