Thu. Apr 25th, 2024

A EditText is an overlay over TextView that configures itself to be editable. It is the predefined subclass of TextView that includes rich editing capabilities.

Every text field expects a certain type of text input, such as an email address, phone number, or just plain text. So it’s important that you specify the input type for each text field in your app so the system displays the appropriate soft input method (such as an on-screen keyboard).

Properties of Edit Text:

For EditText we have some in properties, those are

Ems: The em is simply the font size. In an element with a 2in font, 1em thus means 2in. Expressing sizes, such as margins and paddings, in em means they are related to the font size, and if the user has a big font (e.g., on a big screen) or a small font (e.g., on a handheld device), the sizes will be in proportion. Declarations such as ‘text-indent: 1.5em’ and ‘margin: 1em’ are extremely common in CSS.

Inputtype: Input type specifies which type of input EditText can accept.

Ex: Number, Email, Name etc.

Hint: Showing the information about the EditText.

Ex: Enter your Name, Enter your Password

Plaintext

It can all types of text like character, numeric, symbols etc.

<EditText
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:inputType="textPersonName"
    android:hint="Name"
    android:ems="10"
    android:id="@+id/editText" />

Password

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

Password (Numeric)

<EditText
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:inputType="numberPassword"
    android:ems="10"
    android:id="@+id/editText3" />

Email

<EditText
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:inputType="textEmailAddress"
    android:ems="10"
    android:id="@+id/editText4" />

Phone

<EditText
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:inputType="phone"
    android:ems="10"
    android:id="@+id/editText5" />

Postal Address

<EditText
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:inputType="textPostalAddress"
    android:ems="10"
    android:id="@+id/editText6" />

Multiline Text

<EditText
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:inputType="textMultiLine"
    android:ems="10"
    android:id="@+id/editText7" />

Time

<EditText
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:inputType="time"
    android:ems="10"
    android:id="@+id/editText8" />

Date

<EditText
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:inputType="date"
    android:ems="10"
    android:id="@+id/editText9" />

Number

<EditText
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:inputType="number"
    android:ems="10"
    android:id="@+id/editText10" />

Number (signed)

<EditText
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:inputType="numberSigned"
    android:ems="10"
    android:id="@+id/editText11"/>

Number Decimal

<EditText
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:inputType="numberDecimal"
    android:ems="10"
    android:id="@+id/editText12"/>

By Rajashekar

I’m (Rajashekar) a core Android developer with complimenting skills as a web developer from India. I cherish taking up complex problems and turning them into beautiful interfaces. My love for decrypting the logic and structure of coding keeps me pushing towards writing elegant and proficient code, whether it is Android, PHP, Flutter or any other platforms. You would find me involved in cuisines, reading, travelling during my leisure hours.

Leave a Reply

Your email address will not be published. Required fields are marked *