在講解EditText之前,先介紹一下如何查看android屬性文檔:
1.在SDK api中搜索android
2.在搜索結(jié)果的R.attr中
<EditText
android:id="@+id/edit_text"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
以上默認(rèn)情況下,EditText有焦點(diǎn),軟件盤不彈出.但是如果EditText被ScrollView包裹,軟件盤會(huì)彈出
focusable : Boolean that controls whether a view can take focus.
一個(gè)控件是否可以聚焦 ,這個(gè)主要應(yīng)用在非觸摸屏的android應(yīng)用中
focusableInTouchMode : Boolean that controls whether a view can take focus while in touch mode.
當(dāng)在觸摸模式下,判斷一個(gè)控件是否可以聚焦.
主要用在EditText中,因?yàn)檐浖P會(huì)為擁有焦點(diǎn)的EditText輸入.如果此值設(shè)置為false,鍵盤是不會(huì)彈出的.
windowSoftInputMode :定義了默認(rèn)的軟件盤輸入狀態(tài)
Defines the default soft input state that this window would like when it is displayed. Corresponds to softInputMode.Must be one or more (separated by '|') of the following constant values.
stateUnspecified: 不特別指定,用系統(tǒng)默認(rèn)最好的,默認(rèn)值.
stateUnchanged: 離開軟件盤輸入,不管最后是什么狀態(tài).
stateHidden: 使軟件盤再合適的時(shí)候隱藏(當(dāng)用戶跳向別的頁面) 默認(rèn)應(yīng)該就是這個(gè)值
stateAlwaysHidden: 軟件盤一直隱藏,暫時(shí)看起來與stateHidden沒發(fā)現(xiàn)什么區(qū)別,使用這兩個(gè)屬性,再ScrollView存在的情況下,軟件盤不會(huì)默認(rèn)彈出
stateVisible:使軟件盤在合適的時(shí)候顯示(使用這個(gè)屬性,會(huì)顯示軟件盤,但是進(jìn)入其他頁面再返回默認(rèn)就不顯示了,只有點(diǎn)擊后才會(huì)調(diào)起軟件盤)
stateAlwaysVisable: 當(dāng)窗口有輸入焦點(diǎn)的時(shí)候,軟件盤一直顯示(進(jìn)入其它頁面,在返回焦點(diǎn)存在,軟件盤還會(huì)存在)
adjustUnspecified:窗口的大小/盤調(diào)整沒有被指定腿宰,系統(tǒng)將自動(dòng)選擇調(diào)整大小和 PAN模式胀滚,取決于窗口的內(nèi)容是否有任何布局視圖攒盈,可以滾動(dòng)其內(nèi)容百框。如果有這樣的一個(gè)視圖,然后將窗口調(diào)整大小芒澜,與假定的可調(diào)整大小的面積為軟件盤空出地方
adjustResize:總是調(diào)整窗口大小:減少窗口區(qū)域去顯示軟件盤:實(shí)際效果是鍵盤覆蓋內(nèi)容,如果有ScrollView,就會(huì)將其包裹的內(nèi)容向上移動(dòng),看到鍵入內(nèi)容.
adjustPan:不會(huì)調(diào)整窗口大小,會(huì)已焦點(diǎn)位置移動(dòng)(再EditTextView以上的整體向上移動(dòng)),方便用戶看到他們的鍵入內(nèi)容.有沒有scrollVIew效果都是一樣的,是整體上移
adjustNothing:不會(huì)調(diào)整窗口大小和pan去為軟件盤留位置,窗口不會(huì)調(diào)整他. 沒有ScrollView和adjustResize一樣效果,有的話也不會(huì)調(diào)整
默認(rèn)會(huì)焦點(diǎn)位置移動(dòng),類似adjustPan效果
如果想要默認(rèn)不顯示軟件盤,并且點(diǎn)擊后輸入內(nèi)容顯示,可以按以下設(shè)置:
<activity
android:name=".MainrActivity"
android:label="@string/title_activity_main"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateHidden|adjustResize"></activity>
下面為一個(gè)講解觸摸模式的文章:
http://www.th7.cn/Program/Android/201407/234672.shtml