700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > android开发中EditText自动获取焦点时隐藏hint的代码

android开发中EditText自动获取焦点时隐藏hint的代码

时间:2022-10-14 22:23:34

相关推荐

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"

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。