Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MDRaisedButton doesn't work on android #2371

Closed
kerry41015104 opened this issue Dec 10, 2020 · 3 comments
Closed

MDRaisedButton doesn't work on android #2371

kerry41015104 opened this issue Dec 10, 2020 · 3 comments

Comments

@kerry41015104
Copy link

kerry41015104 commented Dec 10, 2020

I successfully convert python file into apk, but the button doesn't work. The button can work on my computer, I don't know why no response when I'm touching the button.
Here is my python code

from kivymd.app import MDApp
from kivy.core.window import Window
from kivy.uix.screenmanager import Screen
from kivy.properties import StringProperty
from kivymd.uix.snackbar import Snackbar
from kivy.uix.label import Label
from kivy.network.urlrequest import UrlRequest
import certifi
import os




class HomeScreen(Screen):
    pass


class MainApp(MDApp):
    name = StringProperty()
    category = StringProperty()
    area = StringProperty()
    image = StringProperty()
    url = StringProperty()
    youtube = StringProperty()

    def __init__(self,**kwargs):
        Window.size = (1200,1600)
        super().__init__(**kwargs)

    def on_start(self):
        os.environ['SSL_CERT_FILE'] = certifi.where()
        UrlRequest('https://www.themealdb.com/api/json/v1/1/random.php', on_success=self.success, on_failure=self.failure, on_error=self.error)



    def success(self, urlrequest, result):
        ingredient_list = self.root.ids['home'].ids['ingredient_list']
        print(result)
        self.youtube = result['meals'][0]['strYoutube']
        self.name = result['meals'][0]['strMeal']
        self.category = result['meals'][0]['strCategory']
        self.area = result['meals'][0]['strArea']
        self.image = result['meals'][0]['strMealThumb']
        self.url = result['meals'][0]['strSource']
        for i in range(1,21):
            if result['meals'][0][f'strIngredient{i}'] != '':
                l = Label(text=result['meals'][0][f'strIngredient{i}'],color=(0,0,0,1))
                ingredient_list.add_widget(l)



    def error(self, urlrequest):
        print("error")
        Snackbar(text='Url is not available').show()
    def failure(self, urlrequest):
        print("failure")
        Snackbar(text='Url is not available').show()

    **def view(self):**
        if self.url != '' and self.youtube == '':
            Snackbar(
                text=self.url,
                size_hint_x=2
            ).show()
        if self.youtube != '' and self.url == '':
            Snackbar(
                text=self.youtube,
                size_hint_x=2
            ).show()
        if self.youtube != '' and self.url != '':
            Snackbar(
                text=self.youtube,
                size_hint_x=2
            ).show()
        if self.youtube == '' and self.url == '':
            Snackbar(text='Url is not available').show()

MainApp().run()

kv file

ScreenManager:
HomeScreen:
    id:home
    name:'home'

<HomeScreen>:
    FloatLayout:
  
        **MDRaisedButton:**
            pos_hint:{'top':.27,'right':.65}
            size_hint:.3,.05
            text:'View'
            on_press: app.view()
    
        Label:
             text: 'Ingredients'
            font_size:40
            pos_hint:{'top':.23,'right':1}
            size_hint:1,.1
            color:1,0,0,1
        ScrollView:
            pos_hint:{'top':.15,'left':1}
            size_hint:1,.15
            GridLayout:
                id: ingredient_list
                cols:1
                size_hint_y: None
                height: self.minimum_height
                row_default_height:'50dp'
                row_force_default: True

spec file


# (str) Title of your application
title = My MealApp

# (str) Package name
package.name = myMealApp

# (str) Package domain (needed for android/ios packaging)
package.domain = org.test

# (str) Source code where the main.py live
source.dir = .

# (list) Source files to include (let empty to include all the files)
source.include_exts = py,png,jpg,kv,atlas,ttf,db,txt,url

# (list) List of inclusions using pattern matching
#source.include_patterns = assets/*,images/*.png

# (list) Source files to exclude (let empty to not exclude anything)
#source.exclude_exts = spec

# (list) List of directory to exclude (let empty to not exclude anything)
#source.exclude_dirs = tests, bin

# (list) List of exclusions using pattern matching
#source.exclude_patterns = license,images/*/*.jpg

# (str) Application versioning (method 1)
version = 0.1

# (str) Application versioning (method 2)
# version.regex = __version__ = ['"](.*)['"]
# version.filename = %(source.dir)s/main.py

# (list) Application requirements
# comma separated e.g. requirements = sqlite3,kivy
requirements = python3,kivy==2.0.0rc1,kivymd,chardet,idna,certifi,urllib3,requests,openssl,android
@tshirtman
Copy link
Member

It's probably because of the scrollview, you might want to adjust the timeout/distance settings so it's harder to inadvertedely scroll when you want to press a button.

@kerry41015104
Copy link
Author

I try to adjust the distance, but it still doesn't work. Even l remove the scrollview, the button is the same.

@RobertFlatt
Copy link
Contributor

Check that the versions of KivyMD are the same on the desktop and on Android.
If the version is a .dev then the code is only the same if it is installed at the same time on the desktop and running p4a.
If the version is .dev, reinstall KivyMD on the desktop and test if the issue occurs there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants