Android EditText custom border and Border color (reprint)

Source: Internet
Author: User

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)

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.