Android input box control with clear function edittextwithdel

Record a very practical widget edittextwithdel, which is to add a small icon to the right of the input box of the Android system. Clicking the small icon can clear the content in the input box. Because the Android native EditText does not have this function, we need to rewrite EditText to realize this function. The renderings are as follows:

The main idea is to set monitoring for the picture on the right. Click the picture on the right to clear the content of the input box and hide the delete icon. Because we can't directly set the click event for EditText, we simulate the click event by remembering the position we pressed, and use the ontouchevent() method of the input box

Setdrawable() method, setcomposunddrawableswithinterinsicbounds (drawable left, drawable top, drawable right, drawable bottom) to set icons on the top, bottom, left and right. If you don't want to display them in a certain place, set it to null. Next, let's use it to set the layout of the activity, a custom input box and a button

Then is the preparation of interface code, mainly testing the input box

Source code download: http://xiazai.jb51.net/201609/yuanma/EditTextWithDel (jb51.net). rar

The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support programming tips.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>