- 背景:
默认文本框背景是带有下划输入线的。
去掉输入线:android:background="@null"
或自定义其他@drawable…xml背景 - 文本:
(1)输入提示:android:hint=“提示内容”、android:textColorHint=“提示文本颜色”
(2)文本(同textview):android:textColor=“文本颜色”、android:textSize=“字号sp” - 输入限制:
(1)、行数:android:singleLine=“true” 单行
android:maxLines=“1” 最大输入行数(当然还有最小)
(2)、字数:android:maxLength=“16”
代码中设置: editText.setFilters(new InputFilter[]{newInputFilter.LengthFilter(100)});
(3)、内容:android:digits=“可输入的内容”。
android:inputType=“textPassword”(密码、数字、小数…*手机号要另加判断) - Enter键:android: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
actionDone 完成,对应常量EditorInfo.IME_ACTION_DONE - 光标
(1)显示:android:cursorVisible=“true” 在某些机型上默认颜色可能和背景色一致也有可能不显示。
(2)光标:android:textCursorDrawable="@null" 与输入文字颜色一致,也可以定义xml样式。 - *布局文件中设置TextView的android:textAllCaps=”true”文本为大写,然后在代码中去通过Spannable改变文字的颜色可能无效(未验证)。
- 监听事件:
(1)焦点:setOnFocusChangeListener(onFocusChange(View v, boolean hasFocus))
(2)输入:addTextChangedListener(beforeTextChanged(CharSequence s, int start, int count, int after)、
onTextChanged(CharSequence s, int start, int before, int count)、afterTextChanged(Editable s) )
EditText常用属性和注意事项
最新推荐文章于 2020-05-18 16:53:52 发布