Native implementation of toast for Android devices.

# Will be automatically used native implementation of the toast
# if your application is running on an Android device.
# On desktop use `MDSnackbar <>`_

from kivy.lang import Builder

from kivymd.toast import toast
from import MDApp

KV = '''
    md_bg_color: self.theme_cls.backgroundColor

         pos_hint:{"center_x": .5, "center_y": .5}
         on_press: app.show_toast()

             text: "Make toast"

class Example(MDApp):
    def build(self):
        return Builder.load_string(KV)

    def show_toast(self):
        toast("Hello World", True, 80, 200, 0)


API - kivymd.toast.androidtoast#

kivymd.toast.androidtoast.toast(text, length_long=False, gravity=0, y=0, x=0)#

Displays a toast.

  • length_long – the amount of time (in seconds) that the toast is visible on the screen;

  • text – text to be displayed in the toast;

  • length_long – duration of the toast, if True the toast will last 2.3s but if it is False the toast will last 3.9s;

  • gravity – refers to the toast position, if it is 80 the toast will be shown below, if it is 40 the toast will be displayed above;

  • y – refers to the vertical position of the toast;

  • x – refers to the horizontal position of the toast;

Important: if only the text value is specified and the value of the gravity, y, x parameters is not specified, their values will be 0 which means that the toast will be shown in the center.