android 圆角编辑框

来源:互联网 发布:网站80端口如何申请 编辑:程序博客网 时间:2024/04/29 14:21

 

main.xml:

 

view plain
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     android:orientation="vertical"  
  4.     android:layout_width="fill_parent"  
  5.     android:layout_height="fill_parent"  
  6.     >  
  7.     <TextView    
  8.         android:layout_width="fill_parent"   
  9.         android:layout_height="wrap_content"  
  10.         android:gravity="center_horizontal"   
  11.         android:text="圆角编辑框"  
  12.     />  
  13.     <LinearLayout  
  14.         android:layout_width="fill_parent"  
  15.         android:layout_height="wrap_content"  
  16.         android:gravity="center_horizontal"  
  17.         android:orientation="horizontal">  
  18.           
  19.         <EditText  
  20.             android:layout_width="220px"  
  21.             android:layout_height="wrap_content"  
  22.             android:padding="5px"  
  23.             android:background="@drawable/rounded_edittext_states"   
  24.             android:drawableLeft="@drawable/search"  
  25.             android:singleLine="true"  
  26.             android:lines="1"  
  27.         />  
  28.           
  29.         <Button  
  30.             android:layout_width="wrap_content"  
  31.             android:layout_height="wrap_content"  
  32.             android:background="@drawable/button_search_bg"  
  33.         />   
  34.     </LinearLayout>  
  35. </LinearLayout>  
 

 

rounded_edittext_states.xml  :

view plain
  1. <?xml version="1.0" encoding="utf-8"?>   
  2. <!-- res/drawable-hdpi/rounded_edittext_states.xml -->   
  3. <selector xmlns:android="http://schemas.android.com/apk/res/android">   
  4.     <item    
  5.         android:state_pressed="true"    
  6.         android:state_enabled="true"   
  7.         android:drawable="@drawable/rounded_focused" />   
  8.     <item    
  9.         android:state_focused="true"    
  10.         android:state_enabled="true"   
  11.         android:drawable="@drawable/rounded_focused" />   
  12.     <item    
  13.         android:state_enabled="true"   
  14.         android:drawable="@drawable/rounded_edittext" />   
  15. </selector>   
 

 

rounded_edittext.xml   :

 

view plain
  1. <?xml version="1.0" encoding="utf-8"?>   
  2. <!--  res/drawable/rounded_edittext.xml -->   
  3. <shape xmlns:android="http://schemas.android.com/apk/res/android"   
  4.     android:shape="rectangle"   
  5.     android:padding="8dip">   
  6.     <solid android:color="#FFFFFF"/>   
  7.     <corners   
  8.         android:bottomRightRadius="10dip"   
  9.         android:bottomLeftRadius="10dip"   
  10.         android:topLeftRadius="10dip"   
  11.         android:topRightRadius="10dip"/>   
  12. </shape>  
 

 

rounded_edittext_focused.xml    :

 

view plain
  1. <?xml version="1.0" encoding="utf-8"?>   
  2. <!-- res/drawable/rounded_edittext_focused.xml -->   
  3. <shape xmlns:android="http://schemas.android.com/apk/res/android"   
  4.     android:shape="rectangle"   
  5.     android:padding="8dip">   
  6.     <solid android:color="#FFFFFF"/>   
  7.     <stroke android:width="2dip" android:color="#999" />   
  8.     <corners   
  9.         android:bottomRightRadius="10dip"   
  10.         android:bottomLeftRadius="10dip"   
  11.         android:topLeftRadius="10dip"   
  12.         android:topRightRadius="10dip"/>   
  13. </shape>   
 

 

 

工程源码: http://download.csdn.net/source/3409407


原创粉丝点击