默认软键盘不会隐藏在 Nexus 选项卡或虚拟机中

Default soft keyboard does not hide in Nexus tab or Virtual Machine

我正在开发一个应用程序,我在应用程序中使用自定义键盘进行用户输入。问题是当我在 Nexus 选项卡或 Virtual Box 虚拟机上 运行 我的应用程序时,默认软键盘不会隐藏。它甚至不会在 Tab 和 VM 上弹出我的自定义软键盘,但是当我 运行 应用程序在 Android 手机上时它工作正常。我正在使用以下代码隐藏默认软键盘:

public static void hideKeyboard(Context context, View v) {

        try {
            Log.v("hideKeyboard", "Inside hideKeyboard");
            InputMethodManager inputManager = (InputMethodManager) context
                    .getSystemService(Context.INPUT_METHOD_SERVICE);
            Log.v("hideKeyboard", "InputMethodManager created");
            View view = ((Activity) context).getCurrentFocus();

            if (view != null) {
                Log.v("View found:", "nn");
                inputManager.hideSoftInputFromWindow(view.getWindowToken(),
                        InputMethodManager.HIDE_IMPLICIT_ONLY);
                Log.v("HIDE_NOT_ALWAYS:", "nn");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

试试这个代码,这可能有效,因为它与我的虚拟机完美配合

public static void hideKeypad(Activity activity)
{
try
{
    InputMethodManager imm = (InputMethodManager) activity.getSystemService(Activity.INPUT_METHOD_SERVICE);
    // imm.toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY, 0); //
    // hide
    imm.hideSoftInputFromWindow(activity.getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_IMPLICIT_ONLY);
} catch (Exception e)
{
    e.printStackTrace();
}

}

调用如下方法 隐藏键盘(getApplicationContext(), editText.getWindowToken()).

public void hideKeyboard(Context c, IBinder windowToken) {
    InputMethodManager mgr = (InputMethodManager) c
            .getSystemService(Context.INPUT_METHOD_SERVICE);
    mgr.hideSoftInputFromWindow(windowToken, 0);
}