代碼如下:
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:stretchColumns="1" >
<TableRow>
<TextView
android:id="@+id/t1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="用戶名:"
android:textSize="16sp" />
<!-- selectAllOnFocus="true" 獲取焦點而不是將光標移動爲文本的開始位置或者末尾位置 -->
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="請填寫登陸賬號"
android:selectAllOnFocus="true" />
</TableRow>
<TableRow>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="密碼:"
android:textSize="16sp" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="numberPassword" />
</TableRow>
<TableRow>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="年齡:"
android:textSize="16sp" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="number"
android:maxLength="2" />
</TableRow>
<TableRow>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="出生日期:"
android:textSize="16sp" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="date" />
</TableRow>
<TableRow>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="電話:"
android:textSize="16sp" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="phone"
android:selectAllOnFocus="true" />
</TableRow>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="註冊:" />
</TableLayout>
其中selectAllOnFocus="true" 的作用是獲取焦點而不是將光標移動爲文本的開始位置或者末尾位置,但是有這個和沒這個都調試了幾次,沒有感覺到明顯變化。
inputType這個裏面有很多設置輸入數據的類型,當調用inputType="numberPassword"的時候,彈出輸入法默認的就是數字鍵,而不是字母表。
運行效果如下: