Http://liuzhichao.com/p/612.html
Customizing the Android control EditText border background
Liu Zhishu blog ? program? andriod ? Customizing the Android control edittext border background
Posted in andriodOn 2011/06/02by Liuzc
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?
The
first prepares two pictures, one for the background of the edittext after the focus, one for the background without the focus, attention to the 9.png style of the picture, and then a selector_edittext_ in the drawable. Bg.xml 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/edit_pressed" android:state_focused = "true" /> <item android:drawable = "@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:
<edittextAndroid: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=""/>