gpt4 book ai didi

android - 按下回车键后隐藏键盘

转载 作者:行者123 更新时间:2023-11-30 02:56:00 25 4
gpt4 key购买 nike

简单的问题 - 如何在按下回车键/按钮后关闭虚拟键盘?

我试过这个 Handle “Enter” key on Jelly BeanHow to hide keyboard on enter key ,但这些都不适合我。

最佳答案

你有两个选择。

使用 xml:

 <EditText
android:id="@+id/editText1"
android:inputType="text"
android:imeOptions="actionDone"/>

和代码。

edittext.setOnEditorActionListener(new OnEditorActionListener() {
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (event != null&& (event.getKeyCode() == KeyEvent.KEYCODE_ENTER)) {
InputMethodManager in = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
in.hideSoftInputFromWindow(edittext.getApplicationWindowToken(),InputMethodManager.HIDE_NOT_ALWAYS);
}
return false;
}
});

关于android - 按下回车键后隐藏键盘,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23251605/

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