我有一个在 TabHost 中运行的 Activity(扩展 Activity)。我从用户操作启动 Android 电子邮件客户端。如果我点击电子邮件客户端中的“放弃”按钮,电子邮件客户端会退出,但屏幕键盘仍然可见。
我的应用程序上没有 EditTexts,所以不知道为什么键盘会一直亮着。我已经尝试了几次迭代如何在完成一项活动后移除键盘?但是没有运气。有什么想法吗?
代码示例
package com.test.launchmail;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.view.inputmethod.InputMethodManager;
import android.widget.Toast;
public class myEmail extends Activity
{
private final String TAG = "** Email **";
public static void send (Context ctx, String addy, String subject, String body)
{
// check to make sure the entry has a phone number
try
{
// use the builtin chooser for users mail app
Intent sendIntent = new Intent(Intent.ACTION_SEND);
sendIntent.setType("text/plain");
sendIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String [] {addy});
sendIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
sendIntent.putExtra(android.content.Intent.EXTRA_TEXT, body);
ctx.startActivity (Intent.createChooser(sendIntent, "Send via which Application?"));
}
catch (Exception e)
{
Toast.makeText (ctx, "No activity was found to handle this action",Toast.LENGTH_SHORT).show();
}
}
@Override
protected void onPostResume()
{
// This executes, but keyboard still visible.
Log.d ("myEmail", "hiding");
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow (mainApp.tabHost.getCurrentTabView ().getApplicationWindowToken (),imm.HIDE_IMPLICIT_ONLY);
super.onResume ();
}
}