Android隐藏键盘不起作用-无法隐藏软键盘 [英] Android Hide Keyboard Not Working - cannot hide soft keyboard

查看:109
本文介绍了Android隐藏键盘不起作用-无法隐藏软键盘的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Droid Incredible上进行开发(并且也在1.5 AVD Emulator上进行了测试),并且我的标签小部件中的一个标签包括一个列表视图以及一个带有EditText和Send按钮的行(用于聊天功能).单击发送后,我将使用以下方法关闭软键盘,但它不起作用.这与我在其他地方发现的人们认为正确的代码相同.

I'm developing on the Droid Incredible (and have tested on a 1.5 AVD Emulator as well), and one of the tabs in my tab widget consists of a listview and a row with an EditText and a Send button (for a chat feature). I am using the following to close the soft keyboard once I click Send, but it's not working. This is identical to code I've found elsewhere that people have upvoted as correct.

看到我想念的东西吗?

// in Button's onClick():
EditText chatTextBox = (EditText) findViewById(R.id.chat_entry);
// Handle button click ...
chatTextBox.setText("");

InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(chatTextBox.getWindowToken(), InputMethodManager.HIDE_IMPLICIT_ONLY);

我还尝试将标志更改为0.有人知道怎么回事吗?

I also tried changing the flag to 0. No luck. Anyone know what's up??

**** EDIT ****刚意识到我最初使用的是 hideSoftInputFromInputMethod()而不是 hideSoftInputFromWindow().更改它并没有使其起作用...

****EDIT**** Just realized I was originally using hideSoftInputFromInputMethod() instead of hideSoftInputFromWindow(). Changing it didn't make it work though...

推荐答案

将HIDE_IMPLICIT_ONLY更改为0(在我从 hideSoftInputFromInputMethod()更改为 hideSoftInputFromWindow()之后)).

Changing HIDE_IMPLICIT_ONLY to 0 did it (after I changed tohideSoftInputFromWindow() from of hideSoftInputFromInputMethod()).

但是我不确定为什么HIDE_IMPLICIT_ONLY无法正常工作,因为我没有在长按Menu的情况下显式打开键盘.

However I'm not sure why HIDE_IMPLICIT_ONLY isn't working since I am not explicitly opening the keyboard with a long press on Menu.

这篇关于Android隐藏键盘不起作用-无法隐藏软键盘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆