Android - 文本框的输入法控制和默认焦点设置

在开发中,必不可少的会使用到文本框(EditText)来进行数据录入,也就会需要对输入法进行一些控制。
先看下LAYOUT定义文件中的和输入法有关的属性:
属性名
说明
android:inputType
指定输入法的类型,int类型,可以用|选择多个。取值可以参考:android.text.InputType类。取值包括:text,
  textUri, phone,number,等。
android:imeOptions
指定输入法窗口中的回车键的功能,可选值为normal,
  actionNext,actionDone,actionSearch等。部分输入法对此的支持可能不够好。
下面的LAYOUT定义文件举了一些例子说明inputType和imeOptions的使用。
<EditText
android:id="@+id/textNormal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="Normal
text"
android:inputType="text"
android:imeOptions="actionNext"
/>
<EditText
android:id="@+id/textInteger"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="Integer
only"
android:inputType="number"
android:imeOptions="actionNext"
/>
<EditText
android:id="@+id/textPhone"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="Phone
number"
android:inputType="phone"
android:imeOptions="actionNext"
/>
<EditText
android:id="@+id/textEmail"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="Email"
android:imeOptions="actionSend"
android:inputType="textEmailAddress"
/>
<EditText
android:id="@+id/textSite"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="Web
Site"
android:imeOptions="actionDone"
android:inputType="textUri"
/>


有时候也要对intent的默认焦点进行设置,不至于在intent跳转的时候默认焦点(光标)在EditText上,导致进入intent就打开输入法,影响界面美观。
默认焦点的顺序是:从上倒下
从左到右第一个可以输入的控件作为焦点
可以使用:
button.setFocusable(true);
button.requestFocus();
button.setFocusableInTouchMode(true);
也可以:
在EditText前面放置一个看不到的LinearLayout,让他率先获取焦点:
<LinearLayout
android:focusable="true"
android:focusableInTouchMode="true"
android:layout_width="0px"
android:layout_height="0px"/>

转载本站文章请注明,转载自:ADASiteMap的空间[http://www.adasitemap.tk]

本文链接:Android – 文本框的输入法控制和默认焦点设置 | ADASiteMap的空间

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值