Android Use Done button on Keyboard to click button

后端 未结 13 1346
-上瘾入骨i
-上瘾入骨i 2020-12-02 06:30

Ok in my app I have a field for the user to input a number. I have the field set to only accept numbers. When the user clicks on the field it brings up the keyboard. On the

13条回答
  •  难免孤独
    2020-12-02 07:07

    Kotlin and Numeric keyboard

    If you are using the numeric keyboard you have to dismiss the keyboard, it will be like:

    editText.setOnEditorActionListener { v, actionId, event ->
      if (action == EditorInfo.IME_ACTION_DONE || action == EditorInfo.IME_ACTION_NEXT || action == EditorInfo.IME_ACTION_UNSPECIFIED) {
          //hide the keyboard
          val imm = context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
          imm.hideSoftInputFromWindow(windowToken, 0)
          //Take action
          editValue.clearFocus()
          return true
      } else {
          return false
      }
    }
    

提交回复
热议问题