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

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

 

 

 

你可能感兴趣的:(android,layout,Integer,input,login,output)