Some of the Android EditText Property/attribute you must know

Android Edittext view allows you to enter the text and give it as a input to your application , In this Tutorial we will see some of most important property/attribute of edittext view.
 

1. hint


 The hint attribute displays the hint text when the edittext is empty

<EditText
     android:id="@+id/mytext" android:layout_width="fill_parent"  
     android:layout_height="wrap_content" android:hint="Enter your name..."/>

Android EditText Hint



2. editable


The editable attribute takes two kind of values either true/false , by default editable attribute has true value , if you specify false then the edittext will not be editable

<EditText
android:id="@+id/mytext"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:editable="false"/>

Android EditText Editable

3. password


The password attribute allows you to display dots to the text entered in the edittext , this attribute takes two kind of values either true/false ,by default it contains false , if you specify true then the text in edittext will be set to dots.

<EditText
android:id="@+id/mytext"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="password"
android:password="true"/>

Android EditText Password


4. requestFocus


This is not an attribute of edittext but instead it is a tag which must be placed inside the opening and closing tag of the edittext, the requestFocus tag  gives focus to the specified edittext

<EditText
android:id="@+id/editText2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>

<EditText
android:id="@+id/editText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>

<requestFocus />
</EditText>

Android EditText requestfocus


5. lines


The lines attribute makes the edittext to take the specified number of lines to enter the text

<EditText
android:id="@+id/editText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:lines="3" />

Android EditText lines

No comments:

Post a Comment