1. 程式人生 > >我的Android進階之旅------>Android中android:windowSoftInputMode的使用方法

我的Android進階之旅------>Android中android:windowSoftInputMode的使用方法

onf ecif 標簽 ear evel per another not 行為

面試題:怎樣在顯示某個Activity時馬上彈出軟鍵盤?


答案:在AndroidManifest.xml文件裏設置<activity>標簽的android:windowSoftInputMode屬性能夠在顯示Activity時馬上彈出當前輸入法的軟鍵盤(無論是否有獲得焦點的空間)。

設置為:android:windowSoftInputMode="stateVisible|adjustPan" 代碼例如以下:

   <activity
            android:name=".RingstonActivity"
            android:configChanges="orientation|keyboardHidden|screenSize"
            android:windowSoftInputMode="stateVisible|adjustPan"
            android:label="@string/app_name"
            android:theme="@style/AppTheme" >

啟動程序,進入RingstonActivity就彈出了當前的輸入法,本人手機上裝的是搜狗輸入法

技術分享

=================================中文大義例如以下=================================
attributes:android:windowSoftInputMode
活動的主窗體怎樣與包括屏幕上的軟鍵盤窗體交互。

這個屬性的設置將會影響兩件事情:
1> 軟鍵盤的狀態——是否它是隱藏或顯示——當活動(Activity)成為用戶關註的焦點。
2> 活動的主窗體調整——是否降低活動主窗體大小以便騰出空間放軟鍵盤或是否當活動窗體的部分被軟鍵盤覆蓋時它的內容的當前焦點是可見的。


它的設置必須是以下列表中的一個值,或一個”state…”值加一個”adjust…”值的組合。在任一組設置多個值——多個”state…”values,比如&mdash有沒有定義的結果。各個值之間用|分開。比如: <activity android:windowSoftInputMode="stateVisible|adjustResize" . . . >
在這設置的值(除"stateUnspecified"和"adjustUnspecified"以外)將覆蓋在主題中設置的值




以下是這些值的含義:

含義
stateUnspecified 軟鍵盤的狀態(是否它是隱藏或可見)沒有被指定。

系統將選擇一個合適的狀態或依賴於主題的設置。

這個是為了軟件盤行為默認的設置。

stateUnchanged 軟鍵盤被保持不管它上次是什麽狀態,是否可見或隱藏,當主窗體出如今前面時。

stateHidden 當用戶選擇該Activity時,軟鍵盤被隱藏——也就是,當用戶確定導航到該Activity時。而不是返回到它因為離開還有一個Activity。
stateAlwaysHidden 軟鍵盤總是被隱藏的。當該Activity主窗體獲取焦點時。
stateVisible 軟鍵盤是可見的,當那個是正常合適的時(當用戶導航到Activity主窗體時)。

stateAlwaysVisible 當用戶選擇這個Activity時。軟鍵盤是可見的——也就是,也就是,當用戶確定導航到該Activity時,而不是返回到它因為離開還有一個Activity。

adjustUnspecified 它不被指定是否該Activity主窗體調整大小以便留出軟鍵盤的空間,或是否窗體上的內容得到屏幕上當前的焦點是可見的。系統將自己主動選擇這些模式中一種主要依賴於是否窗體的內容有不論什麽布局視圖可以滾動他們的內容。如果有這種一個視圖,這個窗體將調整大小,這種如果可以使滾動窗體的內容在一個較小的區域中可見的。這個是主窗體默認的行為設置。

adjustResize 該Activity主窗體總是被調整屏幕的大小以便留出軟鍵盤的空間。
adjustPan 該Activity主窗體並不調整屏幕的大小以便留出軟鍵盤的空間。相反,當前窗體的內容將自己主動移動以便當前焦點從不被鍵盤覆蓋和用戶能總是看到輸入內容的部分。這個一般是不期望比調整大小,由於用戶可能關閉軟鍵盤以便獲得與被覆蓋內容的交互操作。
歐陽鵬 http://blog.csdn.net/ouyang_peng



========================================官網介紹例如以下========================================

語法例如以下:

<activity
android:windowSoftInputMode=["stateUnspecified",
                                       "stateUnchanged", "stateHidden",
                                       "stateAlwaysHidden", "stateVisible",
                                       "stateAlwaysVisible", "adjustUnspecified",
                                       "adjustResize", "adjustPan"] > 


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.

V alue Description
"stateUnspecified" The state of the soft keyboard (whether it is hidden or visible) is not specified. The system will choose an appropriate state or rely on the setting in the theme.

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" It is unspecified whether the activity‘s main window resizes to make room for the soft keyboard, or whether the contents of the window pan to make the current focus visible on-screen. The system will automatically select one of these modes depending on whether the content of the window has any layout views that can scroll their contents. If there is such a view, the window will be resized, on the assumption that scrolling can make all of the window‘s contents visible within a smaller area.

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 noHistory and windowSoftInputMode, which were added in API Level 3.

====================================================================================

作者:歐陽鵬 歡迎轉載。與人分享是進步的源泉!

轉載請保留原文地址:http://blog.csdn.net/ouyang_peng

====================================================================================

技術分享


我的Android進階之旅------&gt;Android中android:windowSoftInputMode的使用方法