文本框中的输入法控制

Android开发中,必不可少的会使用到文本框(EditText)来进行数据录入,也就会需要对输入法进行一些控制。本文会对输入法的控制进行一些总结。

文本框输入法控制

先看下LAYOUT定义文件中的和输入法有关的属性:

属性名说明
android:inputMethod已被弃用,改为使用inputType
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/textDecimal"
			android:layout_width="fill_parent" android:layout_height="wrap_content"
			android:hint="Decimal only"
			android:inputType="numberDecimal"
			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"
		/>


在模拟器中的表现如下:

 普通文本数字,整型
inputType指定为普通文本inputType指定为数字

可看到,随着inputType的不同,输入法的键盘也自动跟着发生变化,并且在inputType=number时,是不允许输入英文字符的。

注意:android:phoneNumber,android:numeric,这几个属性均已被废弃,不少输入法已经不再支持。直接使用inputType比较好。
另外,在做这种调试时,最好使用Google拼音,或Android键盘来进行,否则imeOptions可能不能政党显示,比如百度输入法在我删除它之前就一直不支持imeOptions。

© 2011, Bing. 版权所有。 所有转载请以链接方式进行。

原地址: http://www.learningandroid.net/blog/foundation/input-method-control-in-edittext/
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值