简体   繁体   English

在 Android Kivy 上隐藏时将键盘绑定到 TextInput

[英]Bind Keyboard to TextInput while it is hidden on Android Kivy

I have created a simple kivy app which is successfully running on windows.我创建了一个简单的 kivy 应用程序,它在 windows 上成功运行。 It takes barcode of products as input and proceed further.它以产品的条形码为输入并继续进行。 I have designed my own keypad for my application + It takes input from Barcode Scanner as well (Scanned barcode is being placed in focused TextInput).我为我的应用程序设计了我自己的键盘 + 它也从条码扫描仪接受输入(扫描的条码被放置在焦点 TextInput 中)。 For this, I have set为此,我设置了

    Config.set('kivy', 'keyboard_mode', 'system')

which works perfectly fine.效果很好。

Now, I want to run this app on android.现在,我想在 android 上运行这个应用程序。 On android, when a TextInput get's focus the android's keyboard becomes visible, which I don't want.在 android 上,当 TextInput 获得焦点时,android 的键盘变得可见,这是我不想要的。 I set TextInput property 'keyboard_mode' to 'managed' for this but it stops putting scanned barcode (from Barcode Scanner) in TextInput (as system keyboard will not be requested now).为此,我将 TextInput 属性'keyboard_mode'设置为'managed' ,但它停止将扫描的条形码(来自 Barcode Scanner)放入 TextInput(因为现在不会请求系统键盘)。

What I want, hide the keyboard but it remain binded with focused TextInput, to access input from Barcode Scanner.我想要的是隐藏键盘,但它仍然与焦点 TextInput 绑定,以访问来自条形码扫描仪的输入。 I am stuck here, any help will be highly appreciated.我被困在这里,任何帮助将不胜感激。

I am using: kivy==2.0.0, python==3.7.9 and buildozer to package application for android.我正在使用:kivy==2.0.0,python==3.7.9 和 buildozer 到 package 应用程序,用于 android。

I have a few ideas but I first want to double check that you've put the Config.set('kivy', 'keyboard_mode', 'system') statement in the right place.我有一些想法,但我首先想仔细检查您是否将Config.set('kivy', 'keyboard_mode', 'system')语句放在正确的位置。

This needs to come before everything , ie the first two lines of your your main.py file should look like this:这需要出现在一切之前,即你的 main.py 文件的前两行应该是这样的:

from kivy.config import Config

Config.set('kivy', 'keyboard_mode', 'system')

from kivy.app import App
from kivy.core.window import Window

# etc.

The reason I ask this, is because writing Config.set() after importing App has no effect.我问这个的原因是因为在导入App后写Config.set()没有效果。 On your computer I believe the default keyboard_mode is '' which is to simply choose the best option, which coincidentally is system .在您的计算机上,我相信默认的keyboard_mode''这只是选择最佳选项,巧合的是system This can give the illusion of a working Config.set() .这可能会产生工作Config.set()的错觉。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM