Kivy TextInput to be above Android keyboard, however rest of screen to stay where it is

China☆狼群 提交于 2020-05-15 19:13:07

问题


I am building a quiz game in Kivy, that has a TextInput option for users at the bottom of the screen. It's at the bottom because the clues for the answers are displayed at the top.

The issue I am having is when I deploy my app to my phone, the Android on-screen keyboard pops up and blocks out nearly half my screen.

I tried the softinput_mode in the Windows package, but this seems to push my entire screen up and so now, the top half of the screen is gone (and users can no longer see the clues).

Is there a way to incorporate this within the FloatLayout where my TextInput box is?

If it helps, here is a sample code that will help you recreate the issue and see what I mean:

main.py:

from kivy.app import App
from kivy.lang import Builder
from kivy.uix.boxlayout import BoxLayout
from kivy.core.window import Window

Window.softinput_mode = "below_target"

class TestBox(BoxLayout):
    pass

class RVTestApp(App):
    def build(self):
        return TestBox()


RVTestApp().run()

.kv file:

<GameWindow>:
    FloatLayout:
        Label:
            pos_hint: {'center_x': 0.5, "center_y": 0.9}
            size_hint: (0.2, 0.5)
            font_size: 80
            color: 0, 0, 0, 1
            text: "TEXT AT TOP OF SCREEN"
        TextInput:
            pos_hint: {'x': 0.25, 'y': 0.05}
            size_hint: (0.3, 0.05)
            id: guess
            multline:False
        Button:
            text: "CHECK BUTTON FOR ANSWERS AT BOTTOM OF SCREEN"
            pos_hint: {"x": 0.6, "y": 0.05}
            size_hint: (0.3, 0.05)

Would really appreciate any help on how to get this bit fixed, thank you!

来源:https://stackoverflow.com/questions/61396416/kivy-textinput-to-be-above-android-keyboard-however-rest-of-screen-to-stay-wher

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!