日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > Android >内容正文

Android

next按钮源码android,Android Edittext 软键盘输入法回车键改成下一步Next

發布時間:2025/3/11 Android 55 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。