WWW.CNMSDN.COM
This document is downloaded from Share.cnmsdn.com
Created By luokelong
Android 文本框中的输入法控制
【提示:请尽量使用 Adobe reader 阅读本文档】
下载更多相关源代码、电子书、工具包请访问:http://share.cnmsdn.com/
我分享的更多移动开发资源:http://share.cnmsdn.com/user/luokelong
在Android开发中,必不可少的会使用到文本框(EditText)来进行数据录入,也就会需要对输入法进行一些控制。本文
会对输入法的控制进行一些
总结
初级经济法重点总结下载党员个人总结TXt高中句型全总结.doc高中句型全总结.doc理论力学知识点总结pdf
。
文本框的输入法控制
先看下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"
1 / 4
WWW.CNMSDN.COM
This document is downloaded from Share.cnmsdn.com
Created By luokelong
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"
/>
在模拟器中的表现如下:
普通文本数字,整型
2 / 4
WWW.CNMSDN.COM
This document is downloaded from Share.cnmsdn.com
Created By luokelong
3 / 4
WWW.CNMSDN.COM
This document is downloaded from Share.cnmsdn.com
Created By luokelong
可看到,随着inputType的不同,输入法的键盘也自动跟着发生变化,并且在inputType=number时,是不允许输入英文
字符的。
注意:android:phoneNumber,android:numeric,这几个属性均已被废弃,不少输入法已经不再支持。直接使用inputTy
pe比较好。
另外,在做这种调试时,最好使用Google拼音,或Android键盘来进行,否则imeOptions可能不能政党显示,比如百度
输入法在我删除它之前就一直不支持imeOptions。
下载更多相关源代码、电子书、工具包请访问:http://share.cnmsdn.com/
我分享的更多移动开发资源:http://share.cnmsdn.com/user/luokelong
Powered by TCPDF (www.tcpdf.org)
4 / 4