我正在用Kivy构建一个问答游戏,该游戏的屏幕底部为用户提供了TextInput选项。它在底部,因为答案的线索显示在顶部。
我遇到的问题是,当我将应用程序部署到手机上时,会弹出Android屏幕键盘,并阻塞近一半的屏幕。
我尝试使用Windows软件包中的softinput_mode
,但这似乎使我的整个屏幕向上推,因此现在屏幕的上半部分不见了(用户不再能看到线索)。
是否可以将其合并到我的TextInput框所在的FloatLayout中?
如果有帮助,下面是一个示例代码,可以帮助您重现问题并了解我的意思:
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文件:
<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)
非常感谢您提供有关如何解决此问题的帮助,谢谢!
答案 0 :(得分:0)
您尝试过下面列出的其他选项吗?
+----------------+-------------------------------------------------------+
| Value | Effect |
+================+=======================================================+
| '' | The main window is left as is, allowing you to use |
| | the :attr:`keyboard_height` to manage the window |
| | contents manually. |
+----------------+-------------------------------------------------------+
| 'pan' | The main window pans, moving the bottom part of the |
| | window to be always on top of the keyboard. |
+----------------+-------------------------------------------------------+
| 'resize' | The window is resized and the contents scaled to fit |
| | the remaining space. |
+----------------+-------------------------------------------------------+
| 'below_target' | The window pans so that the current target TextInput |
| | widget requesting the keyboard is presented just above|
| | the soft keyboard. |
+----------------+-------------------------------------------------------+