原标题:EditText输入类型总结

Android中inputType属性在EditText输入值时启动的虚拟键盘的风格有着重要的作用。这也大大的方便的操作。有时需要虚拟键盘只为字符或只为数字。所以inputType尤为重要。

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:inputType="text"/>

文本类型,多为大写、小写和数字符号。android:inputType= "none"

android:inputType= "text"

android:inputType= "textCapCharacters"字母大写

android:inputType= "textCapWords"首字母大写

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

android:inputType= "textAutoCorrect"自动完成

android:inputType= "textAutoComplete"自动完成

android:inputType= "textMultiLine"多行输入

android:inputType= "textImeMultiLine"输入法多行(如果支持)

android:inputType= "textNoSuggestions"不提示

android:inputType= "textUri"网址

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

android:inputType= "textEmailSubject"邮件主题

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:textColorHint设置提示hint信息的颜色。

数值类型android:inputType= "number"数字

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

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

android:inputType= "phone"拨号键盘

android:inputType= "datetime"时间日期

android:inputType= "date"日期键盘

android:inputType= "time"时间键盘

android:digits 属性, 这种方式可以指出要支持的字符。比如要限制只能输入数字,可以这样:

android:digits= "1234567890."

设置EditText不可输入

布局文件中设置

android:focusable= "false"

Java代码中设置

1.设置为不可编辑

editText.setFocusable( false);

editText.setFocusableInTouchMode( false);

2.设置为可编辑

editText.setFocusableInTouchMode( true);

editText.setFocusable( true);

editText.requestFocus(); 返回搜狐,查看更多

责任编辑:

Logo

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

更多推荐