8、从头学Android之EditText控件

类结构图:

说明: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 控件一样

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值