next按钮源码android,Android Edittext 软键盘输入法回车键改成下一步Next
軟件盤中回車鍵默認功能是換行,但是有時候我們在Edittext中輸完內容后點回車想要把焦點切到下一個Edittext繼續輸入,比如常見的登錄頁面,在輸完用戶名后,點回車調到輸入密碼輸入框繼續輸入。
示例代碼
代碼很簡單,如下所示:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
android:id="@+id/account"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:imeOptions="actionNext"
android:singleLine="true"/>
android:id="@+id/password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:imeOptions="actionDone"
android:singleLine="true"/>
分析
其實重點就以下兩句話
android:imeOptions=”actionNext”
android:singleLine=”true”
android:imeOptions=”actionNext” 表示把回車鍵設置成下一步按鈕,這里不同的輸入法,不同的語言可能按鈕上顯示的文字會些許不同,比如有些手機上回顯示下一步,有的顯示下一個,有的英語輸入法顯示Next,意思大同小異。
android:singleLine=”true”意思是設置Edittext只能輸入一行,要注意的這句話必不可少,否則android:imeOptions=”actionNext”的設置還是無法生效,點擊回車還是會換行。想說用android:maxLines=”1”設置是不是也是等效的,結果發現還是會換行,只能用android:singleLine=”true”,雖然說android:singleLine屬性已經被@Deprecated了。
nextFocusForward
在上面的示例代碼中,輸完賬號后點回車默認焦點是傳遞給下一個Edittext的。假設有三個Edittext,輸完第一個后想跳過第二個Edittext直接輸入第三個呢?這就需要靠nextFocusForward屬性來實現
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
android:id="@+id/edit1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:imeOptions="actionNext"
android:nextFocusForward="@+id/edit3"
android:singleLine="true"/>
android:id="@+id/edit2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:imeOptions="actionNext"
android:singleLine="true"/>
android:id="@+id/edit3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:imeOptions="actionDone"
android:singleLine="true"/>
代碼很簡單,關鍵看第一個Edittext中的android:nextFocusForward=”@+id/edit3”這句話,字面意思就是說下一個獲取焦點的控件。需要注意設置的值寫法是@+id/edit3而不是@id/edit3,少了加號的話無法編譯成功。
創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎總結
以上是生活随笔為你收集整理的next按钮源码android,Android Edittext 软键盘输入法回车键改成下一步Next的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 多核电脑的配件(CPU)
- 下一篇: java 验证码校验_JavaWeb验证