1.绑定EditText
EditText.addTextChangedListener(watcher);
2.添加监听事件
TextWatcher watcher = new TextWatcher() {
private CharSequence temp;
private int editStart;
private int editEnd;
@Override
public void onTextChanged(CharSequence s, int start, int before,
int count) {
// TODO Auto-generated method stub
temp = s;
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
// TODO Auto-generated method stub
// mTextView.setText(s);//将输入的内容实时显示
}
@Override
public void afterTextChanged(Editable s) {
// TODO Auto-generated method stub
editStart = editText.getSelectionStart();
editEnd = editText.getSelectionEnd();
// 当输入长度满足时
if (temp.length() > 0) {
// 按钮可点击背景色为
蓝
button.setBackgroundResource(R.drawable.yuanjiaobiankuang_lan);
button.setClickable(true);
} else {
// 按钮不可点击背景色为
灰
button.setBackgroundResource(R.drawable.yuanjiaobiankuang_hui);
button.setClickable(false);
}
}
};
**********************************************************************************************************************
设置密码是否显示明文:
显示密码:
editText1
.setTransformationMethod(HideReturnsTransformationMethod
.getInstance());
隐藏密码:
editText1
.setTransformationMethod(PasswordTransformationMethod
.getInstance());
----------------------------------------------------------------------------------------------------------------------
在android的输入框里,如果要修改光标的颜色及粗细步骤如下两步即可搞定:
1.在资源文件drawable下新建一个光标控制shape_cursor.xml
<?xml version="1.0" encoding="utf-8"?><shapexmlns:android="http://schemas.android.com/apk/res/android"android:shape="rectangle"><sizeandroid:width="1dp" /><solidandroid:color="#008000" /></shape>
android:textCursorDrawable="@drawable/shape_cursor"
if (count != null) {// 设置光标位置editText0.setSelection(count.length());}
***************************************************************EditText在进入界面后会抢占焦点,在界面再次显示后会再次抢占焦点。原因:解决方案:android:windowSoftInputMode=“stateHidden" 再manifest.xml设置activity后第一次进入就不会在抢占焦点,但是要返回界面后不会再次抢占就需要 在EditText的父级的同级控件注意不是父级控件中找一个,设置成 android:focusable="true" android:focusableInTouchMode=“true”,这样就会截断其的抢占行为。.............................................................................................................................设置为不自动弹出输入法:InputMethodManager imm = (InputMethodManager) getSystemService( MainActivity.this .INPUT_METHOD_SERVICE);getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE| WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
判断edittext是否获取焦点:
editText0.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
//hasFocus:有焦点时
}
});
设置edittext滚动:
textView0.setMovementMethod(ScrollingMovementMethod.getInstance());
隐藏滚动进度条:
android:scrollbars="none"