Android - EditText with cross button in the right side


In many applications, we can see that inside every edittext has a cross button. When clicking it, all texts in our edittext will disappear (clear EditText fast!).
Now, I will show a simple tip to make it, hope this helpful for you!
1. Launch Eclipse and start a new android project.
2. Create a simple activity layout have a EditText with the "style" what we want:

As you can see, I put an EditText and a Button to a FrameLayout and aligned the Button at end of EditText.
3. In activity programmatically code, we must:
- Add a TextWatcher for "listen" EditText changed (the Button will appear when we typing texts).
- Declare click event for Button.
Source code simple like this:

4. Running app:

pic name pic name pic name
(sorry for having ads)

Share


Previous post
« Prev Post
Next post
Next Post »