Thursday 21 September 2017

Android Custom Toast Tutorial with Example using Kotlin

Android Custom Toast

Today we are going to learn how can we make our own custom Toast. Nowadays a lot of apps are using custom toast to show messages to clients. Sometimes it is requirement of design to make a custom toast. Don't worry, it is very simple and easy to create custom toast in android. But the special thing is today we will make the custom toast using kotlin language. Here is the final look of our Toast.
android-tech-point-android-custom-toast
Android Custom Toast with Kotlin - Android Tech Point
Let's start now.

Steps

As I have mentioned earlier that it is very easy to make a toast using the Toast as super class. As we are using kotlin, we can do this by using extended functions of kotlin.
  • Create custom_toast_layout.xml and define the layout for our custom toast.
  • Create a kotlin file and name it Util.kt.
  • Write an extended function createToast() to show the toast. You can pass different properties to change the behavior and layout of the toast.
  • Use your own custom toast anywhere in the project.

Implementation

Here are the simple steps in detail to create the custom toast. 
  • Creat the custom_toast_layout.xml.
  • Second step is to write the extended function for the Toast class.
  • Final step is to use this function. You can access this function from anywhere in your project. Here is how you can use this function.

Final Words

We can customize this function in any way we want according to our requirement. A=That's all. We are done with the custom toast. Happy Coding!! :) You can find the code for the complete project at GitHub. Feel free to discuss anything in the comments or contact me at farooqahamdkhan003@gmail.com.


36 comments:

  1. This comment has been removed by a blog administrator.

    ReplyDelete
  2. Thank you for sharing such great information with us. I really appreciate everything that you’ve done here and am glad to know that you really care about the world that we live in
    java training in chennai | java training in USA

    selenium training in chennai

    ReplyDelete
  3. UiPath Training in Bangalore by myTectra is one the best UiPath Training. myTectra is the market leader in providing Robotic Process Automation on UiPath
    ui path training in bangalore

    ReplyDelete
  4. I have been meaning to write something like this on my website and you have given me an idea. Cheers.
    Blueprism training in Pune

    Blueprism training in Chennai

    ReplyDelete
  5. I respect what you have done here. I like the part where you say you are doing this to give back however I would expect by every one of the remarks this is working for you also. LG Mobile Price in Bangladesh

    ReplyDelete
  6. Infycle Technologies, the No.1 software training institute in Chennai offers the No.1 Data Science course in Chennai for tech professionals and students at the best offers. In addition to the Data Science course, other in-demand courses such as Python, Selenium, Oracle, Java, Python, Power BI, Digital Marketing also will be trained with 100% practical classes. After the completion of training, the trainees will be sent for placement interviews in the top MNC's. Call 7504633633 to get more info and a free demo.

    ReplyDelete