gpt4 book ai didi

java - 在 EditText View 中键入内容后隐藏键盘

转载 作者:行者123 更新时间:2023-12-02 03:51:29 26 4
gpt4 key购买 nike

我遇到了这段代码,但我想知道这段代码的作用是什么,InputMethodManager 到底是什么以及我应该在类中的哪里输入这段代码?它会进入 onCreate() 方法还是我应该创建一个新方法?再说一次,我想了解这个方法是如何工作的。

感谢您提前回答:)我感谢您的帮助

    InputMethodManager inputManager = 
(InputMethodManager) context.
getSystemService(Context.INPUT_METHOD_SERVICE);
inputManager.hideSoftInputFromWindow(
this.getCurrentFocus().getWindowToken(),
InputMethodManager.HIDE_NOT_ALWAYS);

最佳答案

javadoc of InputMethod对此有相当的描述性

Central system API to the overall input method framework (IMF) architecture, which arbitrates interaction between applications and the current input method. You can retrieve an instance of this interface with Context.getSystemService().

在您的特定情况下,您对此用例感兴趣

An input method (IME) implements a particular interaction model allowing the user to generate text. The system binds to the current input method that is use, causing it to be created and run, and tells it when to hide and show its UI. Only one IME is running at a time.

同样来自 hideSoftInputFromWindow的描述你可以提取

public boolean hideSoftInputFromWindow (IBinder windowToken, int flags)

Synonym for hideSoftInputFromWindow(IBinder, int, ResultReceiver) without a result: request to hide the soft input window from the context of the window that is currently accepting input. Parameters

windowToken IBinder: The token of the window that is making the request, as returned by View.getWindowToken().

flags int: Provides additional operating flags. Currently may be 0 or have the HIDE_IMPLICIT_ONLY bit set.

这使得代码中的 this 引用 View,因此该代码是扩展 View 的类的一部分

Here是其用法的示例。

关于java - 在 EditText View 中键入内容后隐藏键盘,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35839746/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com