【问题标题】:Programatically change keyboard from custom android keyboard以编程方式从自定义 android 键盘更改键盘
【发布时间】:2012-06-27 15:09:30
【问题描述】:

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

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

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

谢谢,

埃德

【问题讨论】:

    标签: android ime android-input-method


    【解决方案1】:

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

    【讨论】:

    • 你在哪里找到这个方法?
    • 我不记得在哪里找到它了,但它在扩展 InputMethodService 的类上可用
    • 我用谷歌搜索了很多,但没有成功获得这个命名方法。好的,不管它是什么。但请告诉我您成功将键盘更改为自定义键盘?我有一个关于这个主题的问题,我想改变键盘的主题所以只想知道如何通过编程方式做到这一点?有什么想法吗?喜欢这个play.google.com/store/apps/…
    • 自定义键盘如何获取之前的键盘ID??
    【解决方案2】:

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

    【讨论】:

      【解决方案3】:

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

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2018-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-09-17
        • 2010-09-15
        相关资源
        最近更新 更多