在Android的官方文档当中,对windowSoftInputMode的说明如下:

android:windowSoftInputMode

How the main window of the activity interacts with the window containing the on-screen soft keyboard. The setting for this attribute affects two things:

  • The state of the soft keyboard — whether it is hidden or visible — when the activity becomes the focus of user attention.
  • The adjustment made to the activity's main window — whether it is resized smaller to make room for the soft keyboard or whether its contents pan to make the current focus visible when part of the window is covered by the soft keyboard.

The setting must be one of the values listed in the following table, or a combination of one "state..." value plus one "adjust..." value. Setting multiple values in either group — multiple "state..." values, for example — has undefined results. Individual values are separated by a vertical bar (|). For example:

<activity android:windowSoftInputMode="stateVisible|adjustResize" . . . >

Values set here (other than "stateUnspecified" and "adjustUnspecified") override values set in the theme.

Value

Description

"stateUnspecified"

This is the default setting for the behavior of the soft keyboard.

"stateUnchanged"

The soft keyboard is kept in whatever state it was last in, whether visible or hidden, when the activity comes to the fore.

"stateHidden"

The soft keyboard is hidden when the user chooses the activity — that is, when the user affirmatively navigates forward to the activity, rather than backs into it because of leaving another activity.

"stateAlwaysHidden"

The soft keyboard is always hidden when the activity's main window has input focus.

"stateVisible"

The soft keyboard is visible when that's normally appropriate (when the user is navigating forward to the activity's main window).

"stateAlwaysVisible"

The soft keyboard is made visible when the user chooses the activity — that is, when the user affirmatively navigates forward to the activity, rather than backs into it because of leaving another activity.

"adjustUnspecified"

This is the default setting for the behavior of the main window.

"adjustResize"

The activity's main window is always resized to make room for the soft keyboard on screen.

"adjustPan"

The activity's main window is not resized to make room for the soft keyboard. Rather, the contents of the window are automatically panned so that the current focus is never obscured by the keyboard and users can always see what they are typing. This is generally less desirable than resizing, because the user may need to close the soft keyboard to get at and interact with obscured parts of the window.

This attribute was introduced in API Level 3.

introduced in: API Level 1 for all attributes except for

noHistoryand

windowSoftInputMode, which were added in API Level 3. see also:

<application>



<activity-alias>


Activity的主窗口如何与在屏幕之上的键键盘进行交互呢?这一属性的设置(android:windowSoftInputMode)会影响到一下两点:

  • 键盘的状态。当Acitivity出现在用户面前时,键盘是隐藏还是可见。
  • 活动的主窗口调整——是否减少活动主窗口大小以便腾出空间放软键盘或是否当活动窗口的部分被软键盘覆盖时它的内容的当前焦点是可见的。

设置的内容必须是以下表格当中值的一个,或者是一个以“state+adjust……”组合而成的值。在一组设置设置当中可以设置多个值。使用|用于划分不同的值。例如

<activity android:windowSoftInputMode="stateVisible|adjustResize" . . . >


除了(stateUnspecified和adjustUnspecified)以下值复写了在样式文件当中设置的值





描述

"stateUnspecified"

软键盘的状态(隐藏还是可见)没有确定,系统会根据主题当中的设置选取一个合适的状态。这是软键盘的模式设置。

"stateUnchanged"

当Activity出现在最前面时,软键盘的状态不变,不管是可见还是隐藏。

"stateHidden"

当用户选择Activity时,软键盘会隐藏。也就是,当用户确定导航到该Activity时,而不是返回到它由于离开另一个Activity。

"stateAlwaysHidden"

软键盘总是被隐藏的,当该Activity主窗口获取焦点时。

"stateVisible"

软键盘是可见的,当那个是正常合适的时(当用户导航到Activity主窗口时)。

"stateAlwaysVisible"

当用户选择这个Activity时,软键盘是可见的——也就是,也就是,当用户确定导航到该Activity时,而不是返回到它由于离开另一个Activity。

"adjustUnspecified"


"adjustResize"

该Activity主窗口总是被调整屏幕的大小以便留出软键盘的空间。

"adjustPan"

该Activity主窗口并不调整屏幕的大小以便留出软键盘的空间。相反,当前窗口的内容将自动移动以便当前焦点从不被键盘覆盖和用户能总是看到输入内容的部分。这个通常是不期望比调整大小,因为用户可能关闭软键盘以便获得与被覆盖内容的交互操作。