First show screenshots
Second, the principle analysis and implementation
The first step is to create the following three classes
ClearableEditText extends EditText
ClearableEditTextTouch implements OnTouchListener
ClearableEditTextWatcher implements TextWatcher
The main way to delete icons is to use setCompoundDrawables, where mDrawable is the delete icon file we want to add
The second step is to judge whether there is text in the onTextChanged method of the TextWatcher listening event, and if so, display the clear icon
The third step is to set the listening interface for text cleaning
The fourth step is to clean up the text in the OnTouchListener listening event of the EditText control.
Three, code sharing
http://download.csdn.net/detail/cc_want/9185561