安卓學習筆記:2:用EditView創建一個簡單的註冊頁面

代碼如下:

<?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"的時候,彈出輸入法默認的就是數字鍵,而不是字母表。

    運行效果如下:

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章