EditText

1.EditText属性

1.1常用属性

android:singleLine="true单行输入,使用的时候回车键将不会生效
android:hint="默认提示文本"
android:textColorHint="#95A1AA" //提示的颜色
android:selectAllOnFocus="true"//获得焦点后全选组件内所有文本内容
android:minLines="3"//设置最小行的行数
android:maxLines="10"//最大的行数
android:singleLine="true"//限制EditText只允许单行输入,而且不会滚动
android:cursorVisible="true" //设定光标为显示/隐藏
android:typeface="monospace" //字型,normal, sans, serif, monospace (标准、无衬线字体、衬线字体、等宽字体)

1.2设置输入模式

如密码,数字,字母等android:numeric,或android:phoneNumber已经不建议使用

004.jpg

文本类型,多为大写、小写和数字符号。

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" 时间键盘

1.3.限定设置输入的字符

android:digits="1234567890."//只能输入这些字符`

1.4设置EditText不可输入

android:focusable="false"
android:editable="false"
android:selectAllOnFocus="true" //获得焦点后全选组件内所有文本内容

1.5设置为可以编辑

editText.setFocusableInTouchMode(true);
editText.setFocusable(true); //按照api的说明,第一个语句将自动执行这个语句
editText.requestFocus();

1.6改变输入法中回车按钮的显示内容

android:imeOptions="actionNone"
<!--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;-->
<!--actionPrevious 执行 “上一个”,对应常量IME_ACTION_PREVIOUS;-->
<!--actionDone 执行 “完成”,对应常量EditorInfo.IME_ACTION_DONE-->

参考文章

1.Android edittext 属性inputtype详解
2.你从未见过的EditText属性详解

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。