EditText的一些使用注意点

来源:互联网 发布:淘宝海外叫什么 编辑:程序博客网 时间:2024/05/22 12:44
1.如何对EditText进行setText()的时候使其自动换行 
 
Java代码  收藏代码
  1. <EditText android:layout_width="200dp" android:layout_height="wrap_content"  
  2.         android:id="@+id/input" android:singleLine="false"   
  3.          />  

  我们只要确保singleLine为false的话,并且设置宽度一定,就可以自动换行,注意在这里不要设置
Java代码  收藏代码
  1. input.setInputType(0);  

不然就不会自动换行 

2.在TableLayout中布局一行,设置EditText的xml属性: 
Java代码  收藏代码
  1. <!-- android:shrinkColumns="1" shrinks the 2nd column to fit the window -->  
  2. <!-- android:stretchColumns="1" stretches the 2nd column -->  
  3. <TableLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  4.     android:layout_width="fill_parent" android:layout_height="fill_parent"  
  5.     android:orientation="vertical" android:paddingLeft="5dp"  
  6.     android:paddingRight="5dp" android:stretchColumns="1">  
  7.   
  8.   
  9.     <TableRow android:layout_width="fill_parent"  
  10.         android:layout_height="wrap_content" android:orientation="horizontal">  
  11.         <TextView android:layout_width="wrap_content"  
  12.             android:layout_height="wrap_content" android:text="Email"  
  13.             android:paddingRight="5dp">  
  14.         </TextView>  
  15.         <EditText android:id="@+id/txtEmail" android:layout_width="200dp"  
  16.             android:layout_height="wrap_content" android:textSize="18sp"  
  17.             android:singleLine="false" android:inputType="textEmailAddress">  
  18.         </EditText>  
  19.     </TableRow>  
  20.   
  21.   
  22. </TableLayout>   


3.如何设置EditText隐藏键盘 
 
Java代码  收藏代码
  1. (EditText)mMarket.setInputType(0);  


4.如何设置EditText不被输入法遮盖 
Java代码  收藏代码
  1. getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);  
原创粉丝点击