简体   繁体   English

Android Lollipop强制打开软键盘不接受按键

[英]Android Lollipop forced open soft Keyboard doesn't accept keypresses

I am developing an application communicating with a server and at one point need to force open a keyboard and send the pressed characters on the keyboard to the server. 我正在开发与服务器通信的应用程序,有一次需要强制打开键盘并将键盘上按下的字符发送到服务器。

Everything worked just fine until my phone upgraded to Android Lollipop and now suddenly the keyboard opens, but does not react to any interactions. 一切正常,直到我的手机升级到Android Lollipop ,现在突然键盘打开,但对任何交互都没有反应。 On the other hand all the buttons under the keyboard layout react when i try to type the keyboard letters. 另一方面,当我尝试键入键盘字母时,键盘布局下的所有按钮都会做出反应。 Which means that the keyboard layout is letting everything through. 这意味着键盘布局可以让所有内容通过。

I use a button to open the keyboard: 我使用一个按钮来打开键盘:

public void b_view_keyboard(View view) {
  view.requestFocusFromTouch();

  imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
  imm.toggleSoftInput(InputMethodManager.SHOW_FORCED,0);
}

For reading the pressed buttons I use a regular onKeyDown(int keyCode, KeyEvent event) , which always worked great until the Android Lollipop update. 为了阅读按下的按钮,我使用了常规的onKeyDown(int keyCode, KeyEvent event) ,在Android Lollipop更新之前,它总是非常有用。

I found a different post " Android Lollipop soft keyboard doesn't accept keypresses with GL surface " where the person has got exactly the same problem (also not answered as of 26th of March 2015). 我发现了另一则帖子“ Android Lollipop软键盘不接受带有GL表面的按键 ”,该人遇到了完全相同的问题(截至2015年3月26日也未得到答复)。

I thank everyone who can help me with this annoying issue, 我感谢所有可以帮助我解决这个令人讨厌的问题的人,

Thank you, Edward. 谢谢你,爱德华。

I just figured out that it only occurs in landscape orientation. 我只是发现它仅在横向方向上发生。 For my purpose I am forcing a landscape orientation and then the fullscreen keyboard opens and messes things up. 出于我的目的,我强制采用横向方向,然后打开全屏键盘并将其弄乱。 How can I change the keyboard input type for not having the fullscreen option in code while forcing a keyboard to open? 在强制打开键盘时,如何在代码中没有全屏选项的情况下更改键盘输入类型? Remember that there is not EditText or similar. 请记住,没有EditText或类似的东西。

onKeyDown never worked. onKeyDown从来没有奏效。 That function is for hardware keys only- volume, physical keyboards, etc. The only way that might have worked is if you tricked a keyboard into thinking you were a null input connection and it tried to enter the stupidest possible mode- and I'm not even sure it would work then, and if it did it would only be with a subset of keyboards. 该功能仅适用于硬件键-音量,物理键盘等。唯一可行的方法是,如果您欺骗键盘以为您是空输入连接,并且它尝试进入最愚蠢的模式-我甚至不确定它是否能正常工作,如果能做到,则只能使用一部分键盘。 The only way to reliably get input from a soft keyboard is to have your view return an InputConnection from onCreateInputConnection and to implement the keypress and commit text functions there. 可靠地从软键盘获取输入的唯一方法是让视图从onCreateInputConnection返回InputConnection并在此实现按键和提交文本功能。 Please note that the VAST majority of android keyboards don't implement key-like functionality at all, they do everything via commitText and occasionally composing text, as they're far richer APIs. 请注意,大多数VAST Android键盘根本不实现类似按键的功能,因为它们的API更为丰富,所以它们可以通过commitText以及偶尔编写文本来完成所有操作。

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

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