android EditText有个hint属性,可以在用户没有选择输入框时给予提示
但是这个提示必须是在用户有输入字符后才会消失,似乎不太符合国人习惯,有时还会误导,所以要让用户点击到输入框时hint文本就自动消失,方法是监听焦点事件:
写一个公用的方法:
public static OnFocusChangeListener onFocusAutoClearHintListener = 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);
}
}
};
本文介绍了一种改进Android中EditText组件的方法,使得当用户点击输入框时,hint文本能够立即消失,而不是等到用户开始输入时才消失。通过实现一个自定义的OnFocusChangeListener监听器来达到这一目的。
1147

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



