Android EditText with custom font and clear button
2013-06-25 15:28
696 查看
C’mon, admit it, you’ve always wanted this. Have you ever felt that text clearing in your android application on EditTexts feels… wrong ?
First we need to create our own custom control, extending EditText and adding the following:
an image resource for the Clear button
an TextChangedListener so we only show the Clear button when the EditText contains something
method for setting our custom TypeFace
TouchListener so we detect if the user taped on the Clear button area.
Our project will contain a few things:
Main activity: AndroidTutorialActivity.java
Our custom control: MyEditText
Custom fonts in assets folder
Clear_button_image resource for the button
Main.xml as the main layout.
I’ll just post the entire code with comments and I’m sure you’ll understand it in a second:
Don’t forget to add it in your main layout
Run it and see the result:
So, what do we want to achive?
Plain and simple, a TextView, based on the same principle as the previous TextView tutorial, with custom fonts (from assets folder) and with a Clear button.Proceed with caution…
Of course, if you get a request to use custom fonts in you app, this does not apply only to TextViews, but to all items like Buttons, List Items and EditTexts.First we need to create our own custom control, extending EditText and adding the following:
an image resource for the Clear button
an TextChangedListener so we only show the Clear button when the EditText contains something
method for setting our custom TypeFace
TouchListener so we detect if the user taped on the Clear button area.
Our project will contain a few things:
Main activity: AndroidTutorialActivity.java
Our custom control: MyEditText
Custom fonts in assets folder
Clear_button_image resource for the button
Main.xml as the main layout.
I’ll just post the entire code with comments and I’m sure you’ll understand it in a second:
相关文章推荐
- Android带有删除按钮的EditText:EditTextWithDeleteButton
- Android带有删除按钮的EditText:EditTextWithDeleteButton
- Create a Button with an Image and Text [Android]
- Is there any way to define a min and max value for edittext in android?
- android开发小技巧(1)获取EditText确定button状态
- 常用的Android Widget组件学习①--Button and TextView
- android该怎么办iphone那种画面抖动的动画效果(含有button和EditText)
- Controls over the EditText and the IME in Android
- Android系列之LinearLayout+EditText+Button+AlertDialog
- android中去掉button的边框和EditText中的那条线,并自己画一条线
- Android学习指南之九:Button、TextView、EditView、CheckBox、RadioGroup、ImageView、ImageButton
- Autocompletetextview with custom adapter and filter(Autocompletetextview 用户自定义下拉框样式)
- android 添加一个button并获取editText数据
- 2.Android基础:常见控件----->EditText、Button
- Android 带清除功能的输入框控件EditTextWithDel
- android 添加一个button并获取editText数据
- Android常见控件之TextView、EditView、Button、Menu
- Android之UI--重绘EditText以及实现Button的渐变色
- Android自定义组合控件--EditText和Button组合成带有清空EditText内容功能的复合控件
- Setting Text to Image On Android and Adjudt the text font size based on the android resolution