android:windowSoftInputMode
Activity 的主窗口与包含屏幕软键盘的窗口之间的交互方式。该属性的设置会影响两点内容:
1.当 Activity 成为用户注意的焦点时,软键盘的状态为隐藏还是可见。
2.对 Activity 主窗口所做的调整 — 是否将其尺寸调小,为软键盘腾出空间;或当软键盘遮盖部分窗口时,是否平移其内容以使当前焦点可见。
public static final int windowSoftInputMode
Defines the default soft input state that this window would like when it is displayed. Corresponds to WindowManager.LayoutParams.softInputMode.
Must be one or more (separated by ‘|’) of the following constant values.
ConstantValueDescriptionadjustNothing30Don’t resize or pan the window to make room for the soft input area; the window is never adjusted for it.adjustPan20Don’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.adjustResize10Always resize the window: the content area of the window is reduced to make room for the soft input area.adjustUnspecified0The 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.stateAlwaysHidden3Always make the soft input area hidden when this window has input focus.stateAlwaysVisible5Always make the soft input area visible when this window has input focus.stateHidden2Make the soft input area hidden when normally appropriate (when the user is navigating forward to your window).stateUnchanged1Leave the soft input window as-is, in whatever state it last was.stateUnspecified0Not specified, use what the system thinks is best. This is the default.stateVisible4Make the soft input area visible when normally appropriate (when the user is navigating forward to your window).参考文章:
https://developer.android.com/guide/topics/manifest/activity-element#wsoft
https://developer.android.com/reference/android/R.attr.html#windowSoftInputMode
在AndroidManifest.xml中修改:
增加android:windowSoftInputMode=“adjustPan”,修改后发现无效果,界面依旧被输入法挤压。
增加android:windowSoftInputMode=“adjustNothing”,生效,界面不会被挤压。
<activity android:name=".MainActivity" android:windowSoftInputMode="adjustNothing"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity>