Introduction of a more common usage
The first step: Prepare two pictures with the same size and different colors. The image name is divided into: Editbox_focus.png and editbox_normal.png into the project's drawable folder.
Step Two: Create the My_edittext.xml file under the drawable file with the following contents:
<?xml version= "1.0" encoding= "Utf-8"?>
<selector xmlns:android= "Http://schemas.android.com/apk/res/android" >
<item android:drawable= "@drawable/editbox_focus" android:state_focused= "true"/>
<item android:drawable= "@drawable/editbox_normal"/>
</selector>
Step three: Edit the contents of the Styles.xml file under the values file as follows:
<style name= "My_edittext_style" parent= "@android: Style/widget.edittext" >
<item name= "Android:background" > @drawable/my_edittext</item>
</style>
Fourth step: Set the Style property in the edittext that you want to add the border to as follows:
<edittext
Android:id= "@+id/edittext1"
Android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content"
Android:layout_alignparentleft= "true"
android:layout_aligntop= "@+id/textview1"
Android:ems= "10"
Android:inputtype= "Textpersonname"
style = "@style/my_edittext_style"/>
The above steps are simple custom border settings.
Android EditText custom border and Border color (reprint)