Android的软键盘:如何来操作键盘的看法/关 [英] Android Soft Keyboard: How to manipulate views on keyboard on/off

查看:141
本文介绍了Android的软键盘:如何来操作键盘的看法/关的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个布局具有在最上面的一个大的EditText视图+底部一堆按钮。该的EditText是由收缩而当输入法激活/停用使用adjust_resize扩大。底部的按钮都推高了输入法上面。

I have a layout which has one large EditText view at the top + a bunch of buttons at the bottom. The EditText is made to shrink and expand when the ime is activated/deactivated by using adjust_resize. The buttons at the bottom are pushed up above the ime.

我想隐藏这些按钮时,输入法显示,以提供足够的空间来的EditText视图。

I would like to hide these buttons when the ime displays, to provide enough space for the EditText view.

我至今尝试了以下内容:

I have so far tried the following:

  • 子类的EditText,并提供该活动注册在视图上的OnSizeChanged回调的选项。

  • subclassed EditText and provided the activity the option to register a callback on the view's OnSizeChanged.

用于此回调来改变按钮(实际上是布局容器),以GONE的知名度。

Used this callback to change the visibility of the buttons (actually the layout container) to GONE.

这工作正常,并没有隐藏的按钮后输入法弹出。 但是,EditText上并没有扩展到新的可用空间。 此外,当输入法设置断,的EditText字段现在大于它最初,推画面外(现在示出)的按钮。

This work OK and does hide the buttons when the ime pops up. However, the EditText does not expand into the new available space. Furthermore, when the ime is disposed off, the EditText field is now bigger than it was originally, pushing (the now showing) buttons outside the screen.

我还要补充一点,输入第一个字母到视图时,和输入法显示的文字选项,屏幕重绘和EditText上填补了空白区域。

I should also add that when typing the first letter into the view, and the ime displays the word options, the screen is redrawn and the EditText fills the vacant space.

如何得到这个工作任何想法? 甚至更好,有没有一个简单的解决方案,以我的要求?

Any ideas on how to get this to work? Or even better, is there a simpler solution to my requirement?

谢谢...

注:在我看来,滚动是不是一个好的选择。

NB: In my view, scrolling is not a good option.

推荐答案

我得到这个通过改变上述方法有点工作:

I got this to work by changing the above method a bit:

  • 包裹整个布局具有的FrameLayout

  • Wrapped the entire layout with a FrameLayout

子类中的FrameLayout,并提供该活动注册在布局上的OnMeasure

subclassed the FrameLayout and provided the activity the option to register a callback on the layout's OnMeasure

这使活动的机会之前,这些测量改变看法的知名度。

This gives the activity a chance to change visibility of views before these are measured.

我仍然会很高兴听到简单的解决方案,特别是关于搞清楚键盘是否是目前可见或不可见。 (dumpsys窗口显示这些信息。我们很容易得到它?)

I would still be very happy to hear about simpler solutions, especially in regards to figuring out whether the keyboard is currently visible or not. (dumpsys window shows this information. Can we easily get to it?)

这篇关于Android的软键盘:如何来操作键盘的看法/关的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆