Skip to content

Commit

Permalink
扩展ClearEditText
Browse files Browse the repository at this point in the history
  • Loading branch information
r17171709 committed Jun 16, 2017
1 parent ad8f9a7 commit f762f8c
Showing 1 changed file with 12 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
public class ClearEditText extends EditText implements View.OnTouchListener, View.OnFocusChangeListener, TextWatcher {

Drawable clearDrawable;
OnFocusChangeListener focusChangeListener;

public ClearEditText(Context context) {
this(context, null);
Expand Down Expand Up @@ -45,6 +46,9 @@ public void onFocusChange(View v, boolean hasFocus) {
else {
setClearIconVisible(false);
}
if (focusChangeListener!=null) {
focusChangeListener.onFocusChange(v, hasFocus);
}
}

@Override
Expand Down Expand Up @@ -81,4 +85,12 @@ private void setClearIconVisible(boolean visible) {
Drawable[] drawables=getCompoundDrawables();
setCompoundDrawables(drawables[0], drawables[1], visible?clearDrawable:null, drawables[3]);
}

public interface OnFocusChangeListener {
void onFocusChange(View v, boolean hasFocus);
}

public void setFocusChangeListener(OnFocusChangeListener focusChangeListener) {
this.focusChangeListener = focusChangeListener;
}
}

0 comments on commit f762f8c

Please sign in to comment.