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

For example, we should let us close an on-screen keyboard, after we log in successfully.

In that case, We can close the keybord programmatically. 


==== MainActivity.java ====

package com.example.samplekeypad;


import android.os.Bundle;

import android.app.Activity;

import android.view.Menu;

import android.view.View;

import android.view.View.OnClickListener;

import android.view.inputmethod.InputMethodManager;

import android.widget.Button;

import android.widget.Toast;


public class MainActivity extends Activity {


@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

Button btnCloseKeypad = (Button)findViewById(R.id.btnCloseKeyPad);

btnCloseKeypad.setOnClickListener(new OnClickListener() {

@Override

public void onClick(View v) {

/**

* We can close the on-screen keyboard by using InputMethodManager.

*/

InputMethodManager inputManager = (InputMethodManager)getSystemService(INPUT_METHOD_SERVICE);

inputManager.hideSoftInputFromWindow(v.getWindowToken(), 0);


Toast.makeText(getBaseContext(), "스크린 키보드를 닫습니다.", Toast.LENGTH_SHORT).show();

}

});

}


@Override

public boolean onCreateOptionsMenu(Menu menu) {

// Inflate the menu; this adds items to the action bar if it is present.

getMenuInflater().inflate(R.menu.main, menu);

return true;

}


}


: We can close an on-screen keyboard by calling hideSoftInputFromWindow() method in InputMethodManager Class.


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

Specifying The Keyboard Type  (0) 2014.02.07

+ Recent posts

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