The first step: for a better comparison, prepare two identical edittext (when the activity starts, the focus will be on the first edittext, if you do not want this only need to write a height and broadband of the edittext can be avoided, this does not do so), the code is as follows:
<EditText android:layout_width= "Fill_parent" android:layout_height= "36dip" android:background= "@drawable/bg_edittext" android:padding= "5dip" android: Layout_margin= "36dip" android:textcolorhint= "#AAAAAA" android:textsize= " 15dip " android:singleline=" true " android:hint=" Please enter ... "
Next, create three XML files, respectively, when the input box does not have the focus of the background, the input box when the focus of the background, selector background selector (here to get the input box when to get and lose focus), the code is as follows:
Bg_edittext_normal.xml (when no focus is received)
<?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= "#BDC7D8"/> </shape>
Bg_edittext_focused.xml (when gaining focus)
<?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>
Bg_edittext.xml (selector selector)
<?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/contact_edit_edittext _normal "/> <item android:state_focused=" true "android:drawable=" @drawable/contact_edit_edittext_ Focused "/> </selector>
This will be OK, as follows:
Android EditText Custom Styles