我正在调用一个邮件应用程序代表我的应用程序发送邮件,使用以下代码:
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);
答案 0 :(得分:3)
在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);
}
答案 1 :(得分:2)
//将此添加到Android Manifest文件中的活动将解决您的问题,
<activity android:name=".ur activity name" android:windowSoftInputMode="stateHidden|adjustResize">