Android中EditText的inputType属性的详解

xml的inputtype的值。

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” 不提示

扫描二维码关注公众号,回复: 4196858 查看本文章

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:inputType=”number” 数字

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

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

android:inputType=”phone” 拨号键盘

android:inputType=”datetime” 时间日期

android:inputType=”date” 日期键盘

android:inputType=”time” 时间键盘

edittext其他常用属性,网络上收集的。

android:layout_gravity="center_vertical" 设置控件显示的位置:默认top,这里居中显示,还有bottom android:hint="请输入数字!"设置显示在空间上的提示信息

android:numeric="integer" 设置只能输入整数,如果是小数则是:decimal

android:singleLine="true" 设置单行输入,一旦设置为true,则文字不会自动换行。

android:password="true" 设置只能输入密码

android:textColor = "#ff8c00" 字体颜色

android:textStyle="bold" 字体,bold, italic, bolditalic

android:textSize="20dip" 大小

android:capitalize = "characters" 以大写字母写

android:textAlign="center" EditText没有这个属性,但TextView有 android:textColorHighlight="#cccccc" 被选中文字的底色,默认为蓝色

android:textColorHint="#ffff00" 设置提示信息文字的颜色,默认为灰色

android:textScaleX="1.5" 控制字与字之间的间距

android:typeface="monospace" 字型,normal, sans, serif, monospace

android:background="@null" 空间背景,这里没有,指透明

android:layout_weight="1" 权重,控制控件之间的地位,在控制控件显示的大小时蛮有用的。

android:textAppearance="?android:attr/textAppearanceLargeInverse" 文字外观,这里引用的是系统自带的一个外观,?表示系统是否有这种外观,否则使用默认的外观。不知道这样理解对不对?

通过EditText的layout xml文件中的相关属性来实现:

1. 密码框属性 android:password="true" 这条可以让EditText显示的内容自动为星号,输入时内容会在1秒内变成*字样。

2. 纯数字 android:numeric="true" 这条可以让输入法自动变为数字输入键盘,同时仅允许0-9的数字输入

3. 仅允许 android:capitalize="cwj1987" 这样仅允许接受输入cwj1987,一般用于密码验证 下面是一些扩展的风格属性

android:editable="false" 设置EditText不可编辑

android:singleLine="true" 强制输入的内容在单行

android:ellipsize="end" 自动隐藏尾部溢出数据,一般用于文字内容过长一行无法全部显示时

猜你喜欢

转载自www.cnblogs.com/fu609277362/p/10006320.html
今日推荐