Toast Customization in Android

The Android SDK has some default or standard toasts. In this Android instructional exercise I demonstrate to you how you can make your own personal Custom Toast. Part of this example is creating a customized shape of the toast including an image in the toast (ImageView).

We can change this default execution of Toast , we can change the size , color, style and different properties of the content being shown in Toast.

 

  • We first create the shape of the toast through the XML.
  •   Then we make the Layout XML of the toast.
  • Finally we make the references and start through the Java.

1.  Open your project file in Android and create a new XML file in your resources folder and name it: shape.xml. In this XML file we define a stroke (a border around the toast) we set a solid background color of the toast, and finally set some small curved corners in the toast.

Shape.Xml

2. Now that we have set the shape of the custom toast we need to make the actual layout. Create in your layout folder a XML file called toastcustom.xml.

toastcustom.Xml

3. We need something in our tutorial which initiate the toast message. For this I just made a simple button in our Activity_Main.xml.

Activity_Main.Xml

MainActivity.java

 Output :-

 

About Jaimin Patel

I am a Web Developer. I have been blogging and researching since 1 years and like to share my knowledge and research with the world. Peace..!!

View all posts by Jaimin Patel →

Leave a Reply

Your email address will not be published. Required fields are marked *