Welcome 微信登录

首页 / 操作系统 / Linux / Android开发之EditText控件

类结构图:说明:EditText是一种可编辑输入的控件,,由类结构图可以看到它是TextView的子类。所以它有TextView的一些属性,下面就是一个EditText的样例实战演练: 1、如何设置最多输入N个字符通过:Android:maxLength来设置
  1. <EditText  
  2.   
  3. android:layout_width="fill_parent"  
  4.   
  5. android:layout_height="wrap_content"  
  6.   
  7. android:hint="提示文字"  
  8.   
  9. android:maxLength="4"  
  10.   
  11.   
  12.   
  13. />  
效果:只能输入4个字 2、如何设置只能输入数字?通过android:numeric其值有:integer  signed  decimal
  1. <EditText android:id="@+id/myETxt02" android:layout_width="fill_parent"  
  2.   
  3.       android:layout_height="wrap_content" android:numeric="integer" />  
  4.   
  5.    

 3、如何设置成密码输入形式?通过设置android:password="true"就可以
  1. <EditText android:id="@+id/myETxt02" android:layout_width="fill_parent"  
  2.   
  3.     android:layout_height="wrap_content" android:password="true" />  
效果: 4、如何设置成不可编辑状态方式1:android:editable="false"
  1. <EditText android:id="@+id/myETxt04" android:layout_width="fill_parent"  
  2.   
  3.    android:layout_height="wrap_content" android:editable="false"  
  4.   
  5.    android:text="不可编辑状态" />  
方式2:
  1. myEditText05 = (EditText) findViewById(R.id.myETxt05);  
  2.   
  3.       // 设置成不可编辑状态   
  4.   
  5.       myEditText05.setEnabled(false);  

 这样就相当于TextView 控件一样