隐藏SoftKeyboard在Android 9.0 Pie中不起作用

时间:2019-03-11 14:58:33

标签: android

我有以下代码用于在Android中隐藏软键盘:

getCurrentFocus()

除了Android 9.0以外,其他Android版本都可以正常使用。在Android 9.0中,它无效且软键盘没有隐藏。

1 个答案:

答案 0 :(得分:1)

这是因为public void hideKeyboard() { if (getActivity() != null) { InputMethodManager manager = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE); if (manager != null) { manager.hideSoftInputFromWindow(getActivity().findViewById(android.R.id.content).getWindowToken(), 0); } } } 返回null,即使editText已聚焦。因此没有窗口令牌,没有它我们就无法隐藏键盘。

这里是解决方法:

android.R.id.content

我们从SELECT UserName , IntegrationResults.n.value('UpdateResultDescription[1]','VARCHAR(200)') as UpdateResultDescription FROM MyTable outer apply MyTable.XML_Response.nodes('/IntegrationResults') AS IntegrationResults(n); 获取窗口令牌,而不是从currentFocused View获取窗口令牌。因此,这就像一种魅力。