gpt4 book ai didi

android - 软键盘不隐藏

转载 作者:行者123 更新时间:2023-11-29 15:23:50 24 4
gpt4 key购买 nike

我正在调用一个邮件应用程序来代表我的应用程序发送邮件,使用以下代码:

    final Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("plain/text");
intent.putExtra(Intent.EXTRA_EMAIL, new String[] {
address
});

单击发送按钮后,控件将返回到我的应用程序。现在问题出在编辑邮件时——软键盘会弹出。即使返回到我的应用程序后,软键盘也不会被隐藏。如何在我的应用程序中隐藏此键盘?

我尝试了下面的代码,但它不起作用。

   final InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(mUsernameEdit.getWindowToken(), 0);

最佳答案

在 EditText 上使用 onFocusChangeListener 并在其覆盖方法中添加以下内容

if(!hasFocus) {
<your edittext instance variable>.setFocusable(false);
InputMethodManager imm = (InputMethodManager) getSystemService(Activity.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY, 0);
}

关于android - 软键盘不隐藏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15088404/

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