Android 中 EditText 的 inputType 属性及其他常用属性详解
2017-12-19 14:55
369 查看
一、xml里面调用:
二、Activity 里面调用:
三、xml 的
四、EditText 其他常用属性:
五、 其他
密码框属性 android:password=”true” 这条可以让EditText显示的内容自动为星号,输入时内容会在1秒内变成*字样。
纯数字 android:numeric=”true” 这条可以让输入法自动变为数字输入键盘,同时仅允许0-9的数字输入
仅允许 android:capitalize=”cwj1987” 这样仅允许接受输入cwj1987,一般用于密码验证 下面是一些扩展的风格属性
android:editable=”false” 设置EditText不可编辑
android:ellipsize=”end” 自动隐藏尾部溢出数据,一般用于文字内容过长一行无法全部显示时
<---输入数字-> android:inputType="number"/>
二、Activity 里面调用:
EditText editText=(EditText)findViewById(R.id.edittext); intinputType=InputType.TYPE_CLASS_NUMBER|InputType.TYPE_NUMBER_VARIATION_NORMAL; editText.setInputType(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” ----不提示 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:numeric="integer" 设置只能输入整数,如果是小数则是:decimal android:singleLine="true" 设置单行输入,一旦设置为true,则文字不会自动换行。 android:password="true" 设置只能输入密码 android:textStyle="bold" 字体,bold, italic, bolditalic 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:password=”true” 这条可以让EditText显示的内容自动为星号,输入时内容会在1秒内变成*字样。
纯数字 android:numeric=”true” 这条可以让输入法自动变为数字输入键盘,同时仅允许0-9的数字输入
仅允许 android:capitalize=”cwj1987” 这样仅允许接受输入cwj1987,一般用于密码验证 下面是一些扩展的风格属性
android:editable=”false” 设置EditText不可编辑
android:ellipsize=”end” 自动隐藏尾部溢出数据,一般用于文字内容过长一行无法全部显示时
相关文章推荐
- 【Android常用控件】EditText常用属性【三】:EditText选取操作
- [Android] EditText 的 inputType属性(键盘类型)
- android listview常用属性设置详解
- android EditText与TextView几个常用的属性
- [Android] EditText 的 inputType属性(键盘类型)
- Android RelativeLayout布局之常用属性详解
- Android四种常用布局属性详解
- Android 开发:(七)常用布局属性详解
- [Android] EditText 的 inputType属性(键盘类型)
- Android常用控件TextView的属性详解
- Android edittext 属性inputtype详解
- Android: TextView常用属性的用法详解
- Android ListView,GridView,ScrollView,ProgressBar,SeekBar,RelativeLayout,EditText常用属性
- Android View布局xml常用 属性详解
- android布局中常用属性详解
- android常用组件属性 -- Listview属性详解
- [Android] EditText 的 inputType属性(键盘类型)
- 【Android常用控件】EditText常用属性【一】:空白提示/文本域/特殊字符/数字类型/等属性设置
- [Android] EditText 的 inputType属性
- 【Android常用控件】EditText常用属性【二】:为文本输入框指定软键盘类型和软键盘回车键图标设置