gpt4 book ai didi

java - 使用 getCurrentFocus 或 getSystemService 获取 View 不起作用?

转载 作者:行者123 更新时间:2023-12-02 10:45:54 24 4
gpt4 key购买 nike

我想隐藏键盘:

View view = this.getCurrentFocus();

if (view != null) {
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
}
}
});

现在我遇到了问题,getCurrentFocusgetSystemService 颜色为红色,并且显示:

Cannot resolve method getCurrentFocus() / getSystemService()

我做错了什么?

感谢您的帮助!

最佳答案

这个getSystemService之前应该有一个context:

InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE); // or context

getActivity()或类似代码来获取上下文。

查看代码: Close/hide the Android Soft Keyboard

关于java - 使用 getCurrentFocus 或 getSystemService 获取 View 不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52581663/

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