1.简介
文字输入框
2.常见使用
2.1 设置提示文案
<EditText ...android:hint="请输入您的账号" />
//@string/et_hint 文案定义在strings.xml
<EditText ...android:hint="@string/et_hint" />
2.2 设置提示文案字体颜色
<EditText ...android:textColorHint="@color/colorPrimary" />
2.3 限制输入字符
//限制数字
android:digits="0123456789"
//限制密码输入
android:digits="qwertyuiopasdfghjklzxcvbnm0123456789"
2.4 改变游标颜色
//游标颜色和Theme colorAccent关联
<item name="colorAccent">#000000</item>
2.5 改变游标样式
android:textCursorDrawable="@mipmap/ic_launcher"
//也可以依赖shape的背景,比如添加圆角的游标
<shape xmlns:android="https//schemas.android.com/apk/res/android"/>
<corners android:radius="1dp" />
<solid android:color="#FF0000"/>
<size android:width="1dp"
android:height="16dp"/>
<shape>
2.6 指定弹出的键盘类型
<EditText ...android:inputType="number" />
numberPassword//数字密码键盘
number//数字键盘
3.常见场景
3.1 设置游标到最后位置
//方法1
etUrl.setSelection(etUrl.getText().length());
//方法2
Editable etext = etUrl.getText();
Selection.setSelection(etext, etext.length());
3.2 hint 单独设置文字大小
editText.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
//在文字改变之前
editText.setTextSize(16);
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
//在文字改变的时候
if (TextUtils.isEmpty(s)) {
editText.setTextSize(16);//这里的单位是sp
}else{
editText.setTextSize(30);
}
}
@Override
public void afterTextChanged(Editable s) {
//在文字改变的之后
}
});
6805

被折叠的 条评论
为什么被折叠?



