您的位置:首页 > 移动开发 > Android开发

Android EditText输入格式设置

2016-06-27 10:44 495 查看
在开发的过程中,通常会用到EditText,如何让虚拟键盘来适应输入框中内容的类型,通常我们都会在xml文件中加入android:inputType=""。

android:inputType="none"android:inputType="text"android:inputType="textCapCharacters"//前3个输入普通字符android:inputType="textCapWords"//单词首字母大小

android:inputType="textCapSentences"//仅第一个字母大小

android:inputType="textAutoCorrect"android:inputType="textAutoComplete"//前两个自动完成

android:inputType="textMultiLine"//多行输入

android:inputType="textImeMultiLine"//输入法多行(不一定支持)

android:inputType="textNoSuggestions"//不提示

android:inputType="textUri"//URI格式

android:inputType="textEmailAddress"//电子邮件地址格式

android:inputType="textEmailSubject"//
4000
邮件主题格式

android:inputType="textShortMessage"//短消息格式

android:inputType="textLongMessage"android:inputType="textPersonName"//人名格式

android:inputType="textPostalAddress"//邮政格式

android:inputType="textPassword"//密码格式

android:inputType="textVisiblePassword"//密码可见格式

android:inputType="textWebEditText"//作为网页表单的文本格式

android:inputType="textFilter"//文本筛选格式

android:inputType="textPhonetic"//拼音输入格式

android:inputType="number"//数字格式

android:inputType="numberSigned"//有符号数字格式

android:inputType="numberDecimal"//可以带小数点的浮点格式

android:inputType="phone"//拨号键盘

android:inputType="datetime"android:inputType="date"//日期键盘

android:inputType="time"//时间键盘

1、输入法Enter键图标的设置:

软件盘的界面替换只有一个属性android:imeOptions,这个属性的可以取的值有normal,actionUnspecified,actionNone,actionGo,actionSearch,actionSend,actionNext,actionDone,例如当值为actionNext时enter键外观变成一个向下箭头,而值为actionDone时enter键外观则变成了“完成”两个字。

我们也可以重写enter的事件

 

软键盘的Enter键默认显示的是“完成”文本,通过设置android:imeOptions来改变默认的“完成”文本。这里举几个常用的常量值:

actionUnspecified  未指定,对应常量EditorInfo.IME_ACTION_UNSPECIFIED. 

actionNone 没有动作,对应常量EditorInfo.IME_ACTION_NONE

actionGo 去往,对应常量EditorInfo.IME_ACTION_GO

actionSearch 搜索,对应常量EditorInfo.IME_ACTION_SEARCH   

actionSend 发送,对应常量EditorInfo.IME_ACTION_SEND  

actionNext 下一个,对应常量EditorInfo.IME_ACTION_NEXT  

actionDone 完成,对应常量EditorInfo.IME_ACTION_DONE 

 

(EditorInfo.inputType & EditorInfo.TYPE_CLASS_MASK)可以是许多不同的值,包括:

TYPE_CLASS_NUMBER

TYPE_CLASS_DATETIME

TYPE_CLASS_PHONE

TYPE_CLASS_TEXT
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: