It's important that we specify the appropriate input type that the user expects,such as an email address, phone number, or just plain text when they enter some text in every text field.


We can specify the appropriate input type like the following.

==== activity_main.xml ====

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

    xmlns:tools="http://schemas.android.com/tools"

    android:layout_width="match_parent"

    android:layout_height="match_parent"

    android:background="#ffcccccc"

android:orientation="vertical" >

<!-- The button for closing the keypad -->

<Button 

   android:id="@+id/btnCloseKeyPad"

   android:layout_width="match_parent"

   android:layout_height="wrap_content"

   android:text="closing keypad"

   />

<TextView

android:id="@+id/caption01"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:background="#ff0000ff"

android:text="inputType: text|textCapWords"

android:textStyle="bold"

android:textSize="18dp" 

android:textColor="#ffffffff"

/>

<EditText

android:id="@+id/editTextBox01"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:padding="10px"

android:textSize="16dp"

android:inputType="text|textCapWords

/>

<TextView

android:id="@+id/caption02"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:background="#ff0000ff"

android:text="inputType: number|numberSigned|numberDecimal"

android:textStyle="bold"

android:textSize="18dp" 

android:textColor="#ffffffff"

/>

<EditText

android:id="@+id/editTextBox02"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:padding="10px"

android:textSize="16dp"

android:inputType="number|numberSigned|numberDecimal

/>

<TextView

android:id="@+id/caption03"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:background="#ff0000ff"

android:text="inputType: textEmailAddress"

android:textStyle="bold"

android:textSize="18dp" 

android:textColor="#ffffffff"

/>

<EditText

android:id="@+id/editTextBox03"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:padding="10px"

android:textSize="16dp"

android:inputType="textEmailAddress"

/>

<TextView

android:id="@+id/caption04"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:background="#ff0000ff"

android:text="inputType: textPassword"

android:textStyle="bold"

android:textSize="18dp" 

android:textColor="#ffffffff"

/>

<EditText

android:id="@+id/editTextBox04"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:padding="10px"

android:textSize="16dp"

android:inputType="textPassword"

/>

<TextView

android:id="@+id/caption05"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:background="#ff0000ff"

android:text="inputType: phone"

android:textStyle="bold"

android:textSize="18dp" 

android:textColor="#ffffffff"

/>

<EditText

android:id="@+id/editTextBox05"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:padding="10px"

android:textSize="16dp"

android:inputType="phone"

/>

<TextView

android:id="@+id/caption06"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:background="#ff0000ff"

android:text="inputType: date"

android:textStyle="bold"

android:textSize="18dp" 

android:textColor="#ffffffff"

/>

<EditText

android:id="@+id/editTextBox06"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:padding="10px"

android:textSize="16dp"

android:inputType="date"

/>

<TextView

android:id="@+id/caption07"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:background="#ff0000ff"

android:text="inputType: time"

android:textStyle="bold"

android:textSize="18dp" 

android:textColor="#ffffffff"

/>

<EditText

android:id="@+id/editTextBox07"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:padding="10px"

android:textSize="16dp"

android:inputType="time"

/>

</LinearLayout>


: We can specify the input type for out text field by adding the android:inputType attribute to the EditText element.


Here are several possible values documented with the android:inputType attribute.



'Android > ㄴ on-screen keyboard' 카테고리의 다른 글

Closing an on-screen keyboard  (0) 2014.02.07

+ Recent posts

출처: http://large.tistory.com/23 [Large]