8、从头学Android之EditText控件
16lz
2021-01-23
类结构图:
说明: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 控件一样
更多相关文章
- Android 自定义控件入门篇之自定义验证码
- android的抽屉控件SlidingDrawer的使用
- 控件更新Invalidate和postInvalidate的区别
- Android的UI组件复选框控件CheckBox
- Android自定义View(自定义控件)
- Android控件美化Shape
- Android中ListView控件的简单使用
- 7、从头学Android之TextView控件