[Android] Development of dry goods - technology sharing (implementation of ClearableEditText)

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

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325520206&siteId=291194637