66b52468c121889b900d4956032f1009.png

8种机械键盘轴体对比

本人程序员,要买一个写代码的键盘,请问红轴和茶轴怎么选?

软件盘中回车键默认功能是换行,但是有时候我们在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"/>

wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw==

分析

其实重点就以下两句话android:imeOptions=”actionNext”

android:singleLine=”true”

android:imeOptions=”actionNext” 表示把回车键设置成下一步按钮,这里不同的输入法,不同的语言可能按钮上显示的文字会些许不同,比如有些手机上回显示下一步,有的显示下一个,有的英语输入法显示Next,意思大同小异。

android:singleLine=”true”意思是设置Edittext只能输入一行,要注意的这句话必不可少,否则android:imeOptions=”actionNext”的设置还是无法生效,点击回车还是会换行。想说用android:maxLines=”1”设置是不是也是等效的,结果发现还是会换行,只能用android:singleLine=”true”,虽然说android:[email protected]

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"/>

wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw==

代码很简单,关键看第一个Edittext中的android:nextFocusForward=”@+id/edit3”这句话,字面意思就是说下一个获取焦点的控件。需要注意设置的值写法是@[email protected]/edit3,少了加号的话无法编译成功。

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐