Android EditText 学习笔记
Android Edittext Hint
We can set edittext hint by using edittext ‘android:hint’ property.
Edittext hint is used to display a hint about the edittext.
Example: – When we are creating a login window we will create a textview & editext.
Textview is for input (“Enter the username”).
Editext is for output (“androidpeople”).
By using edittext hint we need not create a textview for input. We can provide input text in edittext hint.
1 | < EditText android:id = "@+id/EditText01" |
2 |
android:layout_height = "wrap_content" |
3 |
android:layout_width = "wrap_content" |
4 |
android:hint = "Enter about edittext" /> |
The Output will look like -
When you start typing in editext the hint will be auto hidden.
Android Edittext Single Line
We can set edittext to be a single line by using the property ‘android:singleLine’.
When we type in more text in edittext it will wrap the content and create another line for the text. To stop creating the new line we need to use edittext ‘android:singleLine’ Property.
Android Edittext Single Line Example:-
1 | < EditText android:id = "@+id/EditText01" |
2 |
android:layout_height = "wrap_content" |
3 |
android:singleLine = "true" |
4 |
android:text = "Edittext example by www.androidpeople.com" |
5 |
android:layout_width = "wrap_content" /> |
Here singleline property is true. So it won’t create a new line in edittext.
The Output will look like
Here the text is ”Edittext example by www.androidpeople.com” but it is showing “Edittext example by www.android” as the singleline property is true.
If singleline property is false , the output will look like
Android Edittext Numeric
We can set edittext to only allow integer values using edittext property ‘numeric’.
1 | < EditText android:text = "435.569" |
2 |
android:id = "@+id/EditText01" |
3 |
android:layout_width = "wrap_content" |
4 |
android:layout_height = "wrap_content" |
5 |
android:numeric = "integer|decimal" /> |
Here the numeric is both ‘interger & decimal’. So it will accept only the integer & decimal values. We will be unable to type characers in edittext.
We can use only 0-9 & ‘.’in edittext
The Output will look like
更多相关文章
- 代码中设置drawableleft
- android 3.0 隐藏 系统标题栏
- Android开发中activity切换动画的实现
- Android(安卓)学习 笔记_05. 文件下载
- Android中直播视频技术探究之—摄像头Camera视频源数据采集解析
- 技术博客汇总
- android 2.3 wifi (一)
- AndRoid Notification的清空和修改
- Android中的Chronometer