2014-11-25 107 views
1

我有一个包含EditText(inputType="number")的对话框。对话框关闭后,我想隐藏键盘,如果对话框的EditText在某个时刻处于Focus状态,则会打开该键盘。关闭三星设备上的对话框后的软键盘

现在的事情是,我有一个可行的方法(至少在一些Nexus设备上),除了三星设备(至少S2,S3)。

final InputMethodManager inputManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); 
inputManager.hideSoftInputFromWindow(getWindow().getDecorView().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS); 

在其他设备上,键盘(仅限数字)在对话框后关闭。 在三星设备的键盘只是改变与所有的字母键盘(inputType="text"),而不是键盘inputType="numbers"。我希望它关闭/隐藏代替。

我不能为活动做类似 getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN) 在后台,因为我需要一个键盘有作为。

有谁知道如何处理这个三星特定问题?

回答

4

使用此代码

InputMethodManager inputMethodManager=(InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE); 
inputMethodManager.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0); 
+1

哇!这工作,答案来得非常快,非常感谢你!我搜查了很多,每个人都提出了相同的答案,但没有成功。我必须等待3分钟,然后我可以将这个答案标记为正确:) – angor 2014-11-25 09:59:48

1

我没有三星设备来测试我的代码,但我使用EditText中的WindowToken来隐藏SoftKeyboard。 我的代码看起来是这样的:

InputMethodManager iM = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE); 
iM.hideSoftInputFromWindow(mEditText.getWindowToken(), 0); 

希望工程:)

+0

我也试过这个,hideSoftInputFromWindow在我的上下文中不会像它应该那样工作。谢谢回答! – angor 2014-11-25 10:04:44