开发者

Android Soft Keyboard: How to manipulate views on keyboard on/off

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.

I would like to hide these buttons wh开发者_如何学Cen the ime displays, to provide enough space for the EditText view.

I have so far tried the following:

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

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

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.

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?

Thanks...

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


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

  • Wrapped the entire layout with a FrameLayout

  • 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.

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?)


Have you tried to call myView.invalidade() ?

I was using the GONE property, but then changed to button.setVisibility(View.INVISIBLE); because I don't have any other stuff on my screen.

on the adjust_resize, you will need to check again when the keyboard has gone and show the buttons again.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜