简体   繁体   English

键盘打开/关闭事件后如何更改视图

[英]How to make view change after keyboard open/close event

From readings, I have the height of the soft keyboard with the onSizeChanged method. 从读数来看,我使用onSizeChanged方法获得了软键盘的高度。 What I want to do is to display a list in place of the soft keyboard when it is closed, and remove the list when the keyboard is required again. 我想要做的是在关闭软键盘时显示一个列表,并在再次需要键盘时删除该列表。

The way I'm doing it at the moment is that when a button is pressed, a list will be made visible and the keyboard dismissed using the InputMethodManager. 我目前的操作方式是,当按下按钮时,将显示一个列表,并使用InputMethodManager关闭键盘。 The problem in the button's onClick method, I set the list to be visible, but the keyboard hiding animation is still ongoing. 按钮的onClick方法存在问题,我将列表设置为可见,但是键盘隐藏动画仍在进行中。 This causes a visible flicker to happen, since the set visible call triggers the layout to be redone, and the list becomes visible while the keyboard is still there, pushing other views out of sight to the top. 这会导致出现可见的闪烁,因为设置的可见调用会触发重做布局,并且列表在键盘还在的时候变得可见,从而将其他视图推到顶部。 After the keyboard animation is finished, other views become visible again, this process causes a visible flicker... 键盘动画结束后,其他视图再次变得可见,此过程导致可见的闪烁...

Anyone got any suggestions on how I should approach this?? 有人对我应该如何处理这个问题有任何建议吗? Pulling my hair at the moment, since setting the list visible during onLayout or onSizeChanged doesn't let the list become visible... 此刻正在拉我的头发,因为在onLayout或onSizeChanged期间将列表设置为可见并不会使列表可见...

Thanks!!! 谢谢!!! Dave. 戴夫

you can implement onConfigurationChanged(Configuration) method in your activity. 您可以在活动中实现onConfigurationChanged(Configuration)方法。 Also, to get this method called you should add information in your manifest file to specify in what situations the method should be called like that: 同样,要调用此方法,您应该在清单文件中添加信息,以指定应在哪种情况下调用该方法,如下所示:

android:configChanges="keyboardHidden|orientation"

Look here for additional details. 在此处查看其他详细信息。

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

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