0

I'm New To Kivymd And working on a small project to learn it myself :)

I found in kivymd KitchenSink Demo to How to use toasts.

Here is The Demo code:

from kivymd.app import MDApp
from kivymd.toast import toast
from kivy.lang import Builder
KV = '''
BoxLayout:
    orientation:'vertical'

    MDToolbar:
        id: toolbar
        title: 'Test Toast'
        md_bg_color: app.theme_cls.primary_color
        left_action_items: [['menu', lambda x: '']]

    FloatLayout:

        MDRaisedButton:
            text: 'TEST KIVY TOAST'
            on_release: app.show_toast()
            pos_hint: {'center_x': .5, 'center_y': .5}

'''


class Test(MDApp):
    def show_toast(self):
        '''Displays a toast on the screen.'''

        toast('Test Kivy Toast')

    def build(self):
        return Builder.load_string(KV)

Test().run()


But The Problem is When I Compiled the exact same code using buildozer to apk it is toasting at the center of the screen when the button is clicked!

Am i doing anything wrong here? The buildozer successfully compiles the apk and the apk opens in my android without any crash, but the toast is not appearing in the bottom of the screen!, Instead it is appearing in the center of the screen.

What am I doing wrong in here?

Here is the ScreenShot When I Compiled The App

Ne1zvestnyj
  • 1,391
  • 1
  • 7
  • 25
XBOT_ADMIN
  • 61
  • 3

1 Answers1

0

You must set the gravity parameter to specify the position. About kivymd android toast arguments you can read here.

from kivymd.app import MDApp
from kivymd.toast import toast

from kivy.lang import Builder
from kivy import platform

KV = """
Screen:
    MDRectangleFlatButton:
        text: "Show toast"
        pos_hint: {"center_x": .5, "center_y": .5}
        on_release: app.toast('Text')
"""


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

    def toast(self, text='', duration=2.5):
        if platform == 'android':
            toast(text=text, gravity=80, length_long=duration)
        else:
            toast(text=text, duration=duration)


Test().run()
Ne1zvestnyj
  • 1,391
  • 1
  • 7
  • 25