最近在开发中,在一个界面,软键盘的弾起会对UI产生影响。具体情况是,在这个界面上会弹出一个带有输入框的dialog(或者theme为dialog的activity),当输入框唤起软键盘,会将后边的界面会被推上去。研究了一下解决办法,大概是两个方面去解决,第一是调整输入法的模式;第二是调整页面布局。
输入法的Mode目前有十种,如下:
1,stateUnspecified:Not specified, use what the system thinks is best. This is the default.
2,stateUnchanged:Leave the soft input window as-is, in whatever state it last was.
3,stateHidden:Make the soft input area hidden when normally appropriate (when the user is navigating forward to your window).
4,stateAlwaysHidden:Always make the soft input area hidden when this window has input focus.
5,stateVisible:Make the soft input area visible when normally appropriate (when the user is navigating forward to your window).
6,stateAlwaysVisible:Always make the soft input area visible when this window has input focus.
7,adjustUnspecified:The window resize/pan adjustment has not been specified, the system will automatically select between resize and pan modes, depending on whether the content of the window has any layout views that can scroll their contents. If there is such a view, then the window will be resized, with the assumption being that the resizeable area can be reduced to make room for the input UI.
8,adjustResize:Always resize the window: the content area of the window is reduced to make room for the soft input area.
9,adjustPan:Don't resize the window to make room for the soft input area; instead pan the contents of the window as focus moves inside of it so that the user can see what they are typing. This is generally less desireable than panning because the user may need to close the input area to get at and interact with parts of the window.
10,adjustNothing
:Don't resize or pan the window to make room for the soft input area; the window is never adjusted for it.
这十种方式还可以组合使用。
我在解决问题的时候就是通过设置AndroidManifest.xml中Android:windowSoftInputMode为adjustNothing
解决的。
还有一种方法就是在对应的layout XML的顶级元素上加一层ScrollView并调整android:windowSoftInputMode = "adjustNothing"。