2

What is the purpose of the method showSoftInput in class InputMethodManager? I am new to android, and well for me the documentation is not very clear :

Explicitly request that the current input method's soft input area be shown to the user, if needed. Call this if the user interacts with your view in such a way that they have expressed they would like to start performing input into it.

From what I have understood it opens the keyboard, am I am right? Why should we use this method, doesn't touching an EditText open automatically the keyboard??

4

1 回答 1

2

不,触摸编辑文本不会自动打开软键盘。这只是默认行为。在引擎盖下,当您触摸编辑文本时,会发生一系列事件。最终,Android 框架将在键盘的 IMS 上调用 showSoftInput。这是键盘决定它出于某种原因不想显示并在未显示时返回 false 的机会。例如,我相信在 Swype 中,如果设备上的硬件键盘已经滑出,我们会忽略这一点,不显示键盘,理论上他们想使用硬件键盘。

大多数时候,您要么在这里使用默认实现,要么做一些小检查,然后回退到默认实现。

于 2017-05-30T15:53:18.120 回答