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 -

edittexthint

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

edittextsingleline

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

edittextsinglelinefalse

 

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

edittextnumeric

 

 

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值