您的位置:首页 > 移动开发 > Android开发

Android EditText 自定义

2016-05-04 17:30 453 查看
1、提示内容颜色
android:textColorHint="@color/text_gray"


2、内容开始位置于左上角

android:textAlignment="textStart"
android:gravity="start"


3、自定义光标颜色和粗细,在res/drawable下新建cursor_sytle 
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<size android:width="1.5dp"/>
<solid android:color="@color/blue"/>
</shape>


3.1 设置EditText的属性:textCursorDrawable

android:textCursorDrawable="@drawable/cursor_style"


3.2 设置EditText的属性:textCursorDrawable="@null"  则光标的颜色与文本的颜色一致

4、监控EditText是否有输入,且获取输入长度

mEditText.addTextChangedListener(textWatcher);
TextWatcher textWatcher = new TextWatcher() {

// TextView textView = (TextView)findViewById(R.id.float_window_add);

@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {

}

@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
if (s.length() != 0){

mAddTextView.setTextColor(getResources().getColor(R.color.blue));   //EditText有输入时,改变textView的颜色
}
}

@Override
public void afterTextChanged(Editable s) {
if (s.length() == 0){
mAddTextView.setTextColor(getResources().getColor(R.color.text_gray));  //输入完毕,若字符长度为空时,为没输入
}
}
};
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: