activity中界面中edittext自動獲取焦點(軟鍵盤彈出)解決

      最近在做開發的時候遇到個比較煩的問題就是 我的某個activity頁面中有editText,在一進去就會調用軟鍵盤,這樣看起來不美觀,所以看了下api

 http://developer.android.com/guide/topics/manifest/activity-element.html(要***)

 

    在<Activity>節點下也就是在manifest文件的配置activity節點的時候需要配置

android:windowSoftInputMode 這個屬性來控制軟鍵盤的模式。我摘錄了一下api  相關軟鍵盤的片段如下:

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 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.

    ValueDescription
    "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.

     

    瀏覽了下大概瞭解下也就是說這個配置主要是做兩件事請

    1、當activity獲取焦點的時候來設置軟鍵盤是否可見。

    2、(在軟鍵盤變小的時候留出空間,或者activity包含一個軟鍵盤佈局同時這個activity獲取焦點的時候【pan 在這裏翻譯的應該是面板,學過java GUI 的都知道有個panle】)調整以適應activity 的大小。

    同時這有很多獨立的屬性可以去設置,如果你想要設置的屬性在其中沒有的話你可以嘗試着用以上的屬性組合一下,只要組合的時候用“|”分開就好了。

  • 跑題了 ,我們要的效果是在當前的activity中有edittext,但是默認不彈出,只有當獲取焦點的時候才彈出軟鍵盤,那麼我們根據屬性可以看下

adjustUnspecified | stateHidden 這個組合起來應該可以達到我們要的效果。因此我們在activity的節點上配置入下:< Activity   android:windowSoftInputMode="stateHidden|adjustUnspecified">

其他的效果可以根據api文檔說明進行設置。

 英語水平有限,歡迎指正錯誤 
 /**
 *
 *  
 **/

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章