In our Android application interface design and, for the sake of the unity of the interface style, we need to customize some of the controls. For example, our app uses the blue style, but Android's EditText control gets the focus and the yellow border background is displayed. So how do you get EditText to show our custom blue background when we get the focus?
First prepare two pictures, one is edittext get the focus of the border background, one is not to get the focus of the background, pay attention to the production of 9.png style picture, and then add a selector_edittext_bg.xml file in drawable, the contents are as follows:
<?xml version= 1.0 " Encoding=" utf-8 "? ><selector xmlns:android=" Http://schemas.android.com/apk/res/android > <item android: Drawable= @drawable/edit_pressed Span style= "color: #800000;" > " Android:state_focused=" true "/> <item android:drawable=" Span style= "color: #800000;" > @drawable/edit_normal /></selector>
Then create a new Style.xml file under the Values folder with the following contents:
<?xml version="1.0" encoding="utf-8"? ><resources > <style name="my_edittext_style" parent="@android: style/ Widget.edittext"> <item name="android:background" > @drawable/selector_edittext_bg</item> </style></resources>
Finally, we can use our new style on the Edittex:
<EditText Android:id="@+id/v_value"style="@style/my_edittext_style"Android:layout_width="0.0dip"Android:layout_height="wrap_content"Android:layout_weight="1"Android:hint="@string/edit_key"android:imeoptions="Actiondone"Android:inputtype=""/>
Android custom Android control edittext border background