Android custom Android control edittext border background

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.