0

I was wondering if anybody here knows in what scenarios will Android show the user an on-screen soft keyboard, and how Android takes into account the different types of hardware keyboards available (KEYBOARD_12KEY, KEYBOARD_QWERTY, and KEYBOARD_NOKEYS).

https://developer.android.com/reference/android/content/res/Configuration#keyboard

Question (PART 1) - Could someone please fill out the following

Note that ??? = [show | hide | do nothing | other]

Scenario 1)
User clicks on a AppCompatEditText and has KEYBOARD_NOKEYS, Android will ??? soft input

Scenario 2)
User clicks on a AppCompatEditText and has KEYBOARD_12KEY, Android will ??? soft input

Scenario 3)
User clicks on a AppCompatEditText and has KEYBOARD_QWERTY, Android will ??? soft input

Question (PART 2) - Is it possible to disable this built-in behavior

Now that you have filled in all the blanks of ??? = [show | hide | do nothing | other], is it possible to disable these built-in Android behaviors? And instead replace them all with custom versions by manually detecting the hardware keyboard type on the device and showing/hiding the soft keyboard inside a View.OnFocusChangeListener?

AlanSTACK
  • 5,525
  • 3
  • 40
  • 99

1 Answers1

1

Whether to display the soft keyboard is actually decided by the soft keyboard. The soft keyboard has a function InputMethodService.onEvaluateInputViewShown(). This function is called when there's a chance to show the soft keyboard. If it returns true, the keyboard will be shown. The default implementation is to look and see if a hardware keyboard exists, and to not display if so. But the soft keyboard can override that to display anyway.

All of this is totally up to the soft keyboard app- whichever keyboard they're using (so behavior can change based on which keyboard the user prefers). There's no way for anything else to override it.

Gabe Sechan
  • 90,003
  • 9
  • 87
  • 127
  • Assuming they are just using the default Android soft keyboard, does that mean the soft input keyboard will only be shown in `Scenario 1`? And hidden in both `Scenario 2` and `Scenario 3`? – AlanSTACK Sep 04 '18 at 07:06
  • There is no "default Android soft keyboard". Every OEM is free to install whatever they want. There's a default behavior for InputMethodService, but there's no way to know what a particular keyboard, even the one Google tends to ship, overrides that function to do. Trying to answer would be a stab in the dark. Although show for scenario 1 is a fairly safe assumption. – Gabe Sechan Sep 04 '18 at 07:08
  • Thank you for your insight. If possible, do you think you could provide a source/link for me to read up on and for confirmation about the behaviour of soft keyboards and input method managers? – AlanSTACK Sep 04 '18 at 07:10
  • https://developer.android.com/reference/android/inputmethodservice/InputMethodService.html#onEvaluateInputViewShown() That's the softkeyboard method that gets called. It describes the default behavior of the function, but any keyboard can override it – Gabe Sechan Sep 04 '18 at 07:11
  • In the provided link, one of the first sentences is *The default implementation returns false when there is no hard keyboard*. Do you have any idea on what *no hard keyboard* means specifically? Just `state == KEYBOARD_NOKEYS`? - implying that `KEYBOARD_12KEY` and `KEYBOARD_QWERTY` would be inapplicable? – AlanSTACK Sep 04 '18 at 07:14
  • No hard keyboard means no physical keyboard. That would be shown as KEYBOARD_NOKEYS. I'm not 100% sure how a bluetooth attached keyboard would change that, its been too many years since I've used this function. – Gabe Sechan Sep 04 '18 at 07:18
  • So a `KEYBOARD_12KEY` would still be considered a hardware keyboard by the default Android implementation? – AlanSTACK Sep 04 '18 at 07:20
  • .... I'm honestly not sure. I tend to think not, as its just numerics. But you'd need to find an actual 12 key device to test, which isn't a common thing. Sorry, my last keyboard was written in 2013. – Gabe Sechan Sep 04 '18 at 07:22
  • Do you have any other links you think might be helpful in understanding the functionality of Android keyboards? Before I close this question. – AlanSTACK Sep 04 '18 at 07:24