Is there any widget like EditText
which contains a cross button, or is there any property for EditText
by which it is created automatically? I want the cross button to delete whatever text written in EditText
.
相关问题
- How can I create this custom Bottom Navigation on
- Bottom Navigation View gets Shrink Down
- How to make that the snackbar action button be sho
- Listening to outgoing sms not working android
- How to create Circular view on android wear?
相关文章
- android开发 怎么把图片放入drawable的文件夹下
- android上如何获取/storage/emulated/下的文件列表
- androidStudio有个箭头不认识
- SQLite不能创建表
- Windows - Android SDK manager not listing any plat
- Animate Recycler View grid when number of columns
- Why is the app closing suddenly without showing an
- Android OverlayItem.setMarker(): Change the marker
For
drawable resource
you can use standard android images :http://androiddrawables.com/Menu.html
For example :
If you happen to use DroidParts, I've just added ClearableEditText.
Here's what it looks like with a custom background & clear icon set to
abs__ic_clear_holo_light
from ActionBarSherlock:Use the following layout:
You can also use the button's id and perform whatever action you want on its onClickListener method.
You can download source here:
https://github.com/GhOsTTT/editTextXbutton
have a nice day
This is a kotlin solution. Put this helper method in some kotlin file-
And then use it as following in the
onCreate
method and you should be good to go-BTW, you have to add
R.drawable.ic_clear
or the clear icon at first. This one is from google- https://material.io/tools/icons/?icon=clear&style=baselineIf you don't want to use custom views or special layouts, you can use 9-patch to make the (X) button .
Example: http://postimg.org/image/tssjmt97p/ (I don't have enough points to post images on StackOverflow)
The intersection of the right and bottom black pixels represent the content area. Anything outside of that area is padding. So to detect that the user clicked on the x you can set a OnTouchListener like so:
According to your needs this solution can work better in some cases. I prefer to keep my xml less complicated. This also helps if you want to have an icon on the left, as you can simply include it in the 9 patch.