功能
EditText用來輸入或者編輯文本內容。比較重要的屬性有:
- inputType,輸入類型,例如text(文本)、textPassword(密碼)、number(整數)、date(日期)、time(時間)、datetime(日期時間)
- maxLength,文本最大長度
- hint,提示內容
顯示文本框
代碼:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="4dp">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="text"
android:hint="請輸入姓名"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:hint="請輸入密碼"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="number"
android:hint="請輸入身份證號"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="date"
android:hint="請輸入出生日期"/>
</LinearLayout>
效果: