androidandroid-edittextimeoptions

Set the button to Done instead of Go in EditText


I'm trying to switch the button in the softkey from "Go" to "Done" and vice-versa. If I just set the imeoption

private fun showDoneOnSoftKeyboard() {
    setImeOptionsOnSoftKeyboard(EditorInfo.IME_ACTION_DONE)
}

private fun showGoOnSoftKeyboard() {
    setImeOptionsOnSoftKeyboard(EditorInfo.IME_ACTION_GO)
}

private fun setImeOptionsOnSoftKeyboard(imeOptions: Int) {
    contractIdInput.imeOptions = imeOptions
}

the button is not changed. I've found that by doing:

private fun setImeOptionsOnSoftKeyboard(imeOptions: Int) {
    val inputType = contractIdInput.inputType
    contractIdInput.inputType = InputType.TYPE_NULL
    contractIdInput.imeOptions = imeOptions
    contractIdInput.inputType = inputType
}

the button is changed. The problem is though that the keyboard settings are reset that means that if I have for example the capslock set after I switch between states (for example from Done to Go) then the capslock is reset.

I have also tried

contractIdInput.imeOptions = imeOptions
val imm = context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
imm.restartInput(contractIdInput)

but this has the same effect.

I tried this one as well:

contractIdInput.setImeActionLabel("Custom text", KeyEvent.KEYCODE_ENTER)

but it does not work either.

Is there any other way to do the same?


Solution

  • It looks like this can't be done. The IME-options are thought to be set statically in the XML or programmatically but they can't be modified dynamically while the user is typing.