Ana
Ana

Reputation: 73

How to get number of rows of native Android soft keyboard?

I'm building a custom keyboard using input method service in Android and I want its height to be as much as native's keyboard as possible but without numbers row and any other rows (such as prediction row or something).

I set the height of my keyboard by using

    getInputMethodWindowRecommendedHeight() 

However, when numbers row is inserted into the native keyboard via Settings, this method returns higher value. I want the height to remain as without numbers row. Is there a way to determine the number of rows in the native keyboard?

Upvotes: 0

Views: 185

Answers (1)

Gabe Sechan
Gabe Sechan

Reputation: 93708

Stop. You're thinking about things wrong. There is no native keyboard on Android. Every OEM chooses their own keyboard. There may be no keyboard installed at all other than yours. There is no way to know what the height of a keyboard is, and the height of a keyboard may change during the use of the keyboard (you can easily change the insets of the keyboard from the keyboard app. Common use cases of this are showing/hiding a suggestions bar, or movable keyboards). In fact there are usecases where the keyboard lies to the OS about its height and uses only a portion of it (example: movable keyboards ferquently claim the full screen, then declare a tocuhable inset covering only their actual area).

In addition, the AOSP default keyboard, even if installed, has no special designation or rights. There is no "native" keyboard, only a default keyboard. Which obviously can have any height it wants. It may even be really tiny, if the user picks something like minimum.

What you want isn't really possible, and isn't going to work. Instead, create the keyboard you want to create, and report your height correctly in onComputeInsets.

Upvotes: 2

Related Questions