简体   繁体   English

如何获取本机Android软键盘的行数?

[英]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). 我正在使用Android中的输入法服务来构建自定义键盘,我希望它的高度尽可能与本机键盘相同,但不包括数字行和任何其他行(例如预测行或其他内容)。

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? 有没有办法确定本机键盘中的行数?

Stop. 停止。 You're thinking about things wrong. 您正在考虑错误的事情。 There is no native keyboard on Android. Android上没有本机键盘。 Every OEM chooses their own keyboard. 每个OEM都会选择自己的键盘。 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. 此外,即使安装了AOSP默认键盘,也没有特殊的名称或权利。 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. 而是创建您要创建的键盘,并在onComputeInsets中正确报告您的高度。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM