简体   繁体   English

按钮显示虚拟键盘?

[英]Button to show virtual keyboard?

I have a ListView and it is possible to use the hardware keyboard to filter out items. 我有一个ListView,可以使用硬件键盘过滤掉项目。 However what should I do for phones that don't have a hardware keyboard and only a virtual one? 但是,对于没有硬件键盘且只有虚拟键盘的手机,我该怎么办? Is there a way to add a button that when pressed, the virtual keyboard shows up? 有没有办法添加按钮,按下时,虚拟键盘出现?

I was able to toggle the on-screen keyboard using the code below. 我可以使用下面的代码切换屏幕键盘。 I hope this is useful to someone. 我希望这对某人有用。

InputMethodManager inputMgr = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
inputMgr.toggleSoftInput(0, 0);

One suggestion could be to just use a text entry box ( EditText ). 一个建议可能是只使用文本输入框( EditText )。 That way a user can in theory type more than one character to narrow the search (and see what they've typed). 这样,用户理论上可以输入多个字符来缩小搜索范围(并查看他们输入的内容)。 To display the on-screen keyboard, all they need do is touch in the textbox. 要显示屏幕键盘,他们只需触摸文本框即可。 If that box was named "Search" or something similar, I believe it would be more intuitive to a user than a button. 如果该框被命名为“搜索”或类似的东西,我相信它对用户而言比对按钮更直观。

There's a convention (for which maybe someone else can provide a reference — I couldn't find anything quickly) that holding the Menu hardware button brings up the soft keyboard. 有一个约定(也许其他人可以提供参考 - 我找不到任何快速的东西)按住菜单硬件按钮会打开软键盘。

Though this is seemingly device dependent. 虽然这似乎取决于设备。 I know it works on the G1, but on my HTC Hero it doesn't work on the home screen (though HTC seem to have messed up a few shortcuts, like holding the Home button). 我知道它适用于G1,但在我的HTC Hero上,它在主屏幕上不起作用(虽然HTC似乎搞砸了一些快捷方式,比如按住Home按钮)。

Anyway, I know other apps like ConnectBot mention and employ this convention for bringing up the virtual keyboard. 无论如何,我知道像ConnectBot这样的其他应用程序提到并使用这个约定来启动虚拟键盘。

Holding the menu-button seems to no longer work in Android 4.0 (IceCreamSandwich). 按住菜单按钮似乎不再适用于Android 4.0(IceCreamSandwich)。 This breaks filterable lists in lots of applications where the user now has no way of filtering the list anymore and needs to eyeball-grep through long, long lists. 这打破了许多应用程序中的可过滤列表,用户现在无法再过滤列表,需要通过长长列表进行眼球搜索。

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

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