只需讓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"