3

我创建了一个 android 自定义键盘。按下一个按钮后,我希望它把键盘改回以前的键盘,大概是使用InputMethodManager.setInputMethod(IBinder token, String id);

但是,我不知道从哪里获取令牌 - usinggetCurrentInputBinding().getConnectionToken()不起作用。

有谁知道在哪里可以找到令牌?

谢谢,

埃德

4

3 回答 3

1

您从视图中获取令牌 by view.getWindowToken()

于 2012-07-27T07:48:32.470 回答
1

事实证明,该switchInputMethod(String id)方法很有效——不需要那个令牌。

于 2012-06-26T21:14:56.700 回答
0

您可以使用此方法获取令牌并激活上次使用的键盘

 private fun switchToLastKeyboard() {
        try {
            val imm: InputMethodManager =
                this.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
            val token = this.window.window!!.attributes.token
            //imm.setInputMethod(token, LATIN);
            imm.switchToLastInputMethod(token)
        } catch (t: Throwable) { // java.lang.NoSuchMethodError if API_level<11
            Log.i("TAG", "onCreateInputView: Throwable " + t.message)
        }

    }
于 2020-11-15T12:25:41.193 回答