[英]Resizing Window in Kivy Android App on softkeyboard with SDL2
I am currently working on an Android App using the Python and the Kivy Framework. 我目前正在使用Python和Kivy Framework开发Android应用程序。 The majority of the screen's real estate is used by a text_input widget. 屏幕的大部分空间都由text_input小部件使用。 I would like to resize this text_input when the android soft keyboard pops ups so that the text_input ends right at the top of the keyboard. 我想在android软键盘弹出时调整此text_input的大小,以便text_input恰好在键盘顶部结束。
To accomplish this I tried to use Window.softinput_mode='resize' and when that didn't work, reference the Window.keyboard_height to do my own resize and positioning. 为此,我尝试使用Window.softinput_mode ='resize',如果该方法不起作用,请参考Window.keyboard_height进行自己的调整大小和定位。 As per the documentation and comment in the Window source code I see that both are not supported when using SDL2 on Android (Kivy 1.9 - 1.10). 根据Window源代码中的文档和注释,我看到在Android(Kivy 1.9-1.10)上使用SDL2时,两者均不受支持。
I tested Window.softinput_mode='below_target' which doesn't seem to do anything and Window.softinput_mode='pan' which works but doesn't give me the correct functionality. 我测试了Window.softinput_mode ='below_target'似乎什么都没做,并且测试了Window.softinput_mode ='pan'可以工作,但没有给我正确的功能。
The last thing I tried is to set Window.softinput_mode='pan' and with a function call that is bound to the on_keyboard event print out the value of Window.top so that if the panning simply shifted the Window location upward, I could use that point of reference to do my positioning and resizing. 我尝试的最后一件事是设置Window.softinput_mode ='pan',并使用绑定到on_keyboard事件的函数调用来打印出Window.top的值,这样,如果平移只是将Window位置向上移动,我可以使用该参考点可做我的定位和调整大小。 However the value of Window.top does not apear to change when panning up. 但是,平移时,Window.top的值不会改变。
The only other stack flow that referenced this issue and gave a working example made use of resize mode which doesn't work using SDL2. 引用此问题并给出工作示例的唯一其他堆栈流程使用了调整大小模式,而调整大小模式不适用于SDL2。
Properly resize main kivy window when soft keyboard appears on android 当软键盘出现在android上时适当调整主Kivy窗口的大小
Is there any work-around to accomplish this functionality or a different provider than SDL2 that will work well on Android? 是否有任何解决方法可以实现此功能,或者与SDL2不同的提供程序可以在Android上正常运行?
It seems to be a bug, so I think first step would be to report it here . 这似乎是一个错误,所以我认为第一步是在这里进行报告。 May be someone will fix it or prompt you workaround. 可能有人会修复它或提示您解决方法。
While googling subject I found this get_keyboard_height()
implementation . 在get_keyboard_height()
主题时,我发现了此get_keyboard_height()
实现 。 Since it's part of android
module, try to add this recipe to your buildozer requirements. 由于它是android
模块的一部分,请尝试将此食谱添加到您的buildozer要求中。 It may fix Window.keyboard_height
or may just provide get_keyboard_height()
function to get correct high manually. 它可以修复Window.keyboard_height
,也可以只提供get_keyboard_height()
函数以手动获得正确的高位。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.