0

I set android:imeOptions="actionSearch" on an EditText. I was testing on the emulator, and pressing the physical enter key did not work as I expected. I thought it would have the same effect as clicking the Search button on the on-screen IME, but it had no effect.

I edited the code like below, and it made pressing the physical enter key triggered the action, but it did not hide the on-screen IME like the Search button. I think I could find a way to manually hide the on-screen IME, too, but I am not sure if this is the right approach. Basically, what I want is "physical enter key = on-screen IME Search button". Instead of manually repeating the Search button's behaviour, isn't there a way to tell the system to treat the two in the same way?

setOnEditorActionListener {
  view, actionId, keyEvent ->
  if(actionId == EditorInfo.IME_ACTION_SEARCH ||
    keyEvent.keyCode == KeyEvent.KEYCODE_ENTER)
  {
    //do action
    true;
  }

https://i.stack.imgur.com/W7ucF.png

Damn Vegetables
  • 11,484
  • 13
  • 80
  • 135

1 Answers1

0

did you add these two lines to your xml

android:imeOptions="actionSearch"
android:maxLines="1"
android:inputType="text"

if so and it still showing i check the maxlines and set to 1 this may help if none of that work i would do as you just said and handle it myself but don't repeat anything all is done in one method by the way you can't trust action search will always hide the keyboard on all Apis you need to make the behavier your self just in Case