EditText去掉游標下劃線以及點選隱藏hint
阿新 • • 發佈:2019-01-07
EditText使用很廣泛,今天使用中需要去掉游標以及下劃線,還需要點選後隱藏hint
去掉下劃線 android:background="@null"
去掉游標 android:cursorVisible="false"
點選後隱藏hint 需要寫一個焦點變化事件監聽
public View.OnFocusChangeListener onFocusAutoClearHintListener = new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
EditText editText=(EditText)v;
if (!hasFocus) {// 失去焦點
editText.setHint(editText.getTag().toString());
} else {
String hint=editText.getHint().toString();
editText.setTag(hint);
editText.setHint("" );
}
}
};
然後再edittext繫結就行了
meditSettingNickName.setOnFocusChangeListener(onFocusAutoClearHintListener);
但是在一進入介面edit就會有焦點所以需要把焦點聚集在別的控制元件上,需要在佈局中給EditText的容器控制元件新增以下兩個屬性,把焦點聚集在容器控制元件上。
android:focusable="true"
android:focusableInTouchMode="true"