The new features of Android4.0 later versions of EditText are in the form of single underlines, but many times we need to add a border that looks more beautiful. Here's how to do it:
It is divided into two parts: the state (normal) when the text is not entered, and the state of the input text (focused).
The following is a EditText control:
<edittext android:layout_width= "fill_parent" android:layout_height= "36dip" Android:backgroun d= "@drawable/edittext" android:padding= "5dip" android:layout_margin= "36dip" Android:textcolorhi Nt= "#AAAAAA" android:textsize= "15dip" android:hint= "@string/asdasd_" android:singleline= "true"/& Gt
where android:background= "@drawable/edittext" is another defined Edittext.xml selector (stored in drawable any folder) the following definition Edittext.xml
<?xml version= "1.0" encoding= "Utf-8"? ><selector xmlns:android= "http://schemas.android.com/apk/res/ Android "> <item android:state_window_focused=" false "android:drawable=" @drawable/edittext_normal "/> ; <item android:state_focused= "true" android:drawable= "@drawable/edittext_focused"/> </selector>
Next, define the Edittext_normal.xml and Edittext_focused.xml files, as follows:
Edittext_normal.xml
<?xml version= "1.0" encoding= "UTF-8"?> <shape xmlns:android= "Http://schemas.android.com/apk/res/android" & Gt <solid android:color= "#FFFFFF"/> <corners android:radius= "3dip"/> <stroke android:width = "1dip" android:color= "#BDC7D8"/> </shape>
Edittext_focused.xml
<?xml version= "1.0" encoding= "Utf-8"? ><shape xmlns:android= "Http://schemas.android.com/apk/res/android" > <solid android:color= "#FFFFFF"/> <corners android:radius= "3dip"/> <stroke android:width = "1dip" android:color= "#728ea3"/> </shape>
Effect: 650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/51/15/wKioL1Ri75KDJ9IqAAEDf25KCAE481.jpg "title=" 2014-11-12 13:23:51 screen. png "alt=" wkiol1ri75kdj9iqaaedf25kcae481.jpg "/>
This article is from the "Cute Xiaopp" blog, make sure to keep this source http://smartxiaopp.blog.51cto.com/9349053/1575658
Restore border to android4.x version of EditText