您好,登錄后才能下訂單哦!
最近在做開發(fā)的時候遇到個比較煩的問題就是 我的某個activity頁面中有editText,在一進去就會調(diào)用軟鍵盤,這樣看起來不美觀,所以看了下api
http://developer.android.com/guide/topics/manifest/activity-element.html(要×××)
在<Activity>節(jié)點下也就是在manifest文件的配置activity節(jié)點的時候需要配置
android:windowSoftInputMode
這個屬性來控制軟鍵盤的模式。我摘錄了一下api 相關(guān)軟鍵盤的片段如下:
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.
Value | 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.
瀏覽了下大概了解下也就是說這個配置主要是做兩件事請
1、當activity獲取焦點的時候來設(shè)置軟鍵盤是否可見。
2、(在軟鍵盤變小的時候留出空間,或者activity包含一個軟鍵盤布局同時這個activity獲取焦點的時候【pan 在這里翻譯的應(yīng)該是面板,學過java GUI 的都知道有個panle】)調(diào)整以適應(yīng)activity 的大小。
同時這有很多獨立的屬性可以去設(shè)置,如果你想要設(shè)置的屬性在其中沒有的話你可以嘗試著用以上的屬性組合一下,只要組合的時候用“|”分開就好了。
跑題了 ,我們要的效果是在當前的activity中有edittext,但是默認不彈出,只有當獲取焦點的時候才彈出軟鍵盤,那么我們根據(jù)屬性可以看下
adjustUnspecified | stateHidden 這個組合起來應(yīng)該可以達到我們要的效果。因此我們在activity的節(jié)點上配置入下:< Activity android:windowSoftInputMode="stateHidden|adjustUnspecified">
其他的效果可以根據(jù)api文檔說明進行設(shè)置。 英語水平有限,歡迎指正錯誤 /** * * **/
免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。