Kotlin Android Custom ToastIn the previous example, Kotlin Android Toast we display a simple toast message. We can also able to customize our message which will show as a toast. In the toast, we can display String text, image or both and customize the position of it. Kotlin Android Custom Toast ExampleIn this example, we will display text and an image as a custom toast on clicking the Button. activity_main.xmlAdd the following code in the activity_main.xml file. In this file, we added a Button to perform a click action. custom_toast.xmlCreate a layout file named as custom_toast.xml and add an ImageView and TextView to display as a toast message. Set an image to ImageView and place a message in TextView. MainActivity.ktIn this MainActivity.kt class, we are getting the View object using the layoutInfleter.infalate() method. Clicking on the button displays the toast message with image and text. The custom layout is added over toast by calling the View using the instance of Toast class (as myToast.view = layout). The above code performing the following tasks:
Output: Next Topic# |