xml属性:
android:maxLines="" //最大行数
android:maxLength="" //最大字符数
android:hint="" //placeholder
android:textColorHint="" //placeholder的颜色
android:drawableLeft="" //加一张图片 对应right
android:drawablePadding="" //文字和图片间距
android:textColor="" //字体颜色
android:textSize="" //字体大小
android:inputType="" //键盘类型
android:imeOptions="actionDone" //设置键盘右下角功能;
注意:要使android:imeOptions
起作用,必须能加上android:inputType
属性,
或加上android:singleLine="true"(已废弃)
,但用android:maxLines="1"
不可以
android:imeOptions | 文字 |
---|---|
actionGo | 开始 |
actionNext | 下一步 |
actionSearch | 搜索 |
actionSend | 发送 |
actionDone | Enter符号 |
不自动获得焦点,点击以后弹出键盘:
父控件添加属性
android:focusable="true"
android:focusableInTouchMode="true"
设置监听(kotlin):
et_title.addTextChangedListener(object : TextWatcher {
override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {
}
override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {
}
override fun afterTextChanged(s: Editable?) {
}
})