| | |
| | | */ |
| | | public final class ClearEditText extends AppCompatEditText |
| | | implements View.OnTouchListener, |
| | | View.OnFocusChangeListener, TextWatcher { |
| | | View.OnFocusChangeListener { |
| | | |
| | | private Drawable mClearDrawable; |
| | | |
| | |
| | | setDrawableVisible(false); |
| | | super.setOnTouchListener(this); |
| | | super.setOnFocusChangeListener(this); |
| | | super.addTextChangedListener(this); |
| | | super.addTextChangedListener(new TextWatcher() { |
| | | @Override |
| | | public void onTextChanged(CharSequence s, int start, int before, int count) { |
| | | setDrawableVisible(s.length() > 0); |
| | | } |
| | | |
| | | @Override |
| | | public void beforeTextChanged(CharSequence s, int start, int count, int after) {} |
| | | |
| | | @Override |
| | | public void afterTextChanged(Editable s) {} |
| | | }); |
| | | } |
| | | |
| | | private void setDrawableVisible(boolean visible) { |
| | |
| | | * {@link TextWatcher} |
| | | */ |
| | | |
| | | @Override |
| | | public void onTextChanged(CharSequence s, int start, int before, int count) { |
| | | if (isFocused()) { |
| | | setDrawableVisible(s.length() > 0); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void beforeTextChanged(CharSequence s, int start, int count, int after) {} |
| | | |
| | | @Override |
| | | public void afterTextChanged(Editable s) {} |
| | | |
| | | } |
| | | |