我正在 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)
非常感谢有关如何修复此问题的任何帮助,谢谢!
您是否尝试过下面列出的其他选项?
+----------------+-------------------------------------------------------+
| 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. |
+----------------+-------------------------------------------------------+
我找到了这个问题的解决方案 Erik Sandberg 的 YouTube 频道:
from kivy.core.window import Window
Window.softinput_mode = "target_bellow"
只需将其写入代码中的任何位置即可工作。
根据基维医生的说法,这是低于目标,这意味着桑德伯格他只是犯了错误