android开发中EditText自动获取焦点时隐藏hint的代码
只需让EditText设置以下的OnFocusChangeListener就可以了
private OnFocusChangeListener mOnFocusChangeListener = new OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus)
{
EditText textView = (EditText)v;
String hint;
if (hasFocus) {
hint = textView.getHint().toString();
textView.setTag(hint);
textView.setHint("");
} else {
hint = textView.getTag().toString();
textView.setHint(hint);
}
}
};
一进入一个页面, EditText默认就会自动获取焦点。解决之道:找一个EditText的父级控件,设置成
android:focusable="true"
android:focusableInTouchMode="true"