1

重要的

我正在开发一个应用程序,我在其中集成了用于表情符号的虚拟键盘,使用InputMethodService. 现在,我可以从我的虚拟键盘切换到默认软键盘,如下所示:

emojiKeyboard.switchToPreviousInputMethod();

emojiKeyboard的对象在哪里EmojiKeyboardServiceextends InputMethodService

方法switchToPreviousInputMethod()如下:

public void switchToPreviousInputMethod() {
    Vibrator vib = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
    vib.vibrate(25);
    try {
        previousInputMethodManager.switchToLastInputMethod(iBinder);
    } catch (Throwable t) { // java.lang.NoSuchMethodError if API_level<11
        Context context = getApplicationContext();
        CharSequence text = "Unfortunately input method switching isn't supported in your version of Android! You will have to do it manually :(";
        int duration = Toast.LENGTH_SHORT;
        Toast toast = Toast.makeText(context, text, duration);
        toast.show();
    }
}

因此,切换到我的虚拟键盘令人头疼。有没有办法以编程方式做到这一点?因为我可以再次从设备设置中设置它。

但是,我们知道用户不应该每次切换到默认软键盘时都必须进入设置。

请指导。希望得到肯定的答复。

谢谢。

4

0 回答 0