【问题标题】:Kivy TextInput to be above Android keyboard, however rest of screen to stay where it isKivy TextInput 位于 Android 键盘上方,但屏幕其余部分保持原位
【发布时间】:2020-04-23 20:29:19
【问题描述】:

我正在 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)

非常感谢有关如何修复此问题的任何帮助,谢谢!

【问题讨论】:

    标签: python kivy kivy-language


    【解决方案1】:

    您是否尝试过下面列出的其他选项?

    +----------------+-------------------------------------------------------+
    | 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.                                    |
    +----------------+-------------------------------------------------------+
    

    【讨论】:

      【解决方案2】:

      我在 Erik Sandberg 的 YouTube 频道找到了这个问题的解决方案:

      from kivy.core.window import Window
      Window.softinput_mode = "target_bellow"
      

      只需在代码中的任何位置写下它即可。

      【讨论】:

      • 你的意思是below_target?还是target_below
      • "target_bellow"
      • 除了“bellow”拼写错误之外,这与指定below_targetKivy's own documentation for softinput_mode 不一致(如@Nuzhin Ivan's previous answer 中所述)。此外,我可以在 Google 上找到对 target_bellowonly 参考是您在此线程上的答案。你确定你的意思是target_bellow吗?如果有,您的信息来源是什么?
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-01-04
      • 1970-01-01
      • 2020-08-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多