类结构图:

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

更多相关文章

  1. 第17天android:《android从零开始》视频(1-5)
  2. Android(安卓)EditView
  3. Android下模拟按键输入
  4. [RK3399][Android7.1] 调试笔记 --- 设置搜狗为开机默认输入法
  5. Android(安卓)EditText不弹出软键盘
  6. Android(安卓)Spinner与setDropDownViewResource
  7. Android入门学习笔记之人机用户界面
  8. 解决Android编辑框在全屏模式下无法检测布局变化的问题
  9. Android(安卓)系统广播Action一览验证

随机推荐

  1. centos 磁盘管理详解
  2. f-string 竟然能有 73 个例子,我要学习下
  3. 7 个省时高效的 pytest 特性和插件
  4. Android中JSON解析
  5. 再来 6 个例子教你重构 Python 代码
  6. Django2.0+小程序技术打造微信小程序助手
  7. 再次为王!Python 是 2020 年度编程语言
  8. android用jdbc多线程操作sqlite小结
  9. C语言的一些练习以及自己写一个猜数字小
  10. 算法面试专题课(Java版)