类结构图:说明:EditText是一种可编辑输入的控件,,由类结构图可以看到它是TextView的子类。所以它有TextView的一些属性,下面就是一个EditText的样例实战演练: 1、如何设置最多输入N个字符通过:Android:maxLength来设置
- <EditText
-
- android:layout_width="fill_parent"
-
- android:layout_height="wrap_content"
-
- android:hint="提示文字"
-
- android:maxLength="4"
-
-
-
- />
效果:只能输入4个字 2、如何设置只能输入数字?通过android:numeric其值有:integer signed decimal
- <EditText android:id="@+id/myETxt02" android:layout_width="fill_parent"
-
- android:layout_height="wrap_content" android:numeric="integer" />
-
-
3、如何设置成密码输入形式?通过设置android:password=
"true"就可以
- <EditText android:id="@+id/myETxt02" android:layout_width="fill_parent"
-
- android:layout_height="wrap_content" android:password="true" />
效果: 4、如何设置成不可编辑状态方式1:android:editable=
"false"- <EditText android:id="@+id/myETxt04" android:layout_width="fill_parent"
-
- android:layout_height="wrap_content" android:editable="false"
-
- android:text="不可编辑状态" />
方式2:
- myEditText05 = (EditText) findViewById(R.id.myETxt05);
-
- // 设置成不可编辑状态
-
- myEditText05.setEnabled(false);
这样就相当于TextView 控件一样