我有一个活动(扩展活动)在tabhost中运行。我从用户操作启动android电子邮件客户端。如果我在电子邮件客户端中单击“放弃”按钮,电子邮件客户端将退出,但屏幕键盘将保持可见。
我的应用程序上没有编辑文本,所以不知道为什么键盘不动。我已经尝试了几次How do I remove the keyboard after I finish an activity?的迭代,但是没有成功。有什么想法吗?
代码样本

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 ();
    }
}

最佳答案

好伤心好烦人。我找了一整天,终于在29种不同方法的线索下找到了答案。每个人都声称通过不同的inputMethodManager变体获得了成功。值得一提的是,这个对我很有用。
希望有一天会有一个标准的api调用来实现这一点。

09-11 18:59
查看更多