EditText常用属性
android:password="true"
输入的内容会在1秒内变成"*"字样式
android:numeric="true"
只允许输入0-9的数字输入
android:capitalize="abcde"
仅接受输入abcde,一般用于密码验证
android:hint="密码"
设置提示输入信息
android:single="true"
设置单行输入,这样就不会自动换行
EditText imeOptions属性(改变“回车”键默认样式)
actionUnspecified 未指定 EditorInfo.IME_ACTION_UNSPECIFIED
actionNone 动作 EditorInfo.IME_ACTION_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
EditText默认软键盘 回车换行解决方式:
方式一:设置android:imeoptions属性
方式二:设置为单行输入--》android:singleLine="true"
方式三:在activity中添加监听(kotlin)
editView.setOnEditorActionListener(
TextView.OnEditorActionListener{v,actionId,event->
if(actionId==EditorInfo.IME_ACTION_SEARCH){
//EditorInfo.IME_ACTION_SEARCH要和EditText的imeOptions属性一样
//TODO...
//处理业务逻辑
return @OnEditorActionListener true//返回true,消费这个事件
}
false
}