Restore border to android4.x version of EditText

Source: Internet
Author: User

The new features of Android4.0 later versions of EditText are in the form of single underlines, but many times we need to add a border that looks more beautiful. Here's how to do it:

It is divided into two parts: the state (normal) when the text is not entered, and the state of the input text (focused).

The following is a EditText control:

<edittext android:layout_width= "fill_parent" android:layout_height= "36dip" Android:backgroun d= "@drawable/edittext" android:padding= "5dip" android:layout_margin= "36dip" Android:textcolorhi Nt= "#AAAAAA" android:textsize= "15dip" android:hint= "@string/asdasd_" android:singleline= "true"/& Gt

where android:background= "@drawable/edittext" is another defined Edittext.xml selector (stored in drawable any folder) the following definition Edittext.xml

<?xml version= "1.0" encoding= "Utf-8"? ><selector xmlns:android= "http://schemas.android.com/apk/res/ Android "> <item android:state_window_focused=" false "android:drawable=" @drawable/edittext_normal "/>      ; <item android:state_focused= "true" android:drawable= "@drawable/edittext_focused"/> </selector>

Next, define the Edittext_normal.xml and Edittext_focused.xml files, as follows:

Edittext_normal.xml

<?xml version= "1.0" encoding= "UTF-8"?> <shape xmlns:android= "Http://schemas.android.com/apk/res/android" &          Gt <solid android:color= "#FFFFFF"/> <corners android:radius= "3dip"/> <stroke android:width = "1dip" android:color= "#BDC7D8"/> </shape>

Edittext_focused.xml

<?xml version= "1.0" encoding= "Utf-8"? ><shape xmlns:android= "Http://schemas.android.com/apk/res/android" > <solid android:color= "#FFFFFF"/> <corners android:radius= "3dip"/> <stroke android:width = "1dip" android:color= "#728ea3"/> </shape>

Effect: 650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/51/15/wKioL1Ri75KDJ9IqAAEDf25KCAE481.jpg "title=" 2014-11-12 13:23:51 screen. png "alt=" wkiol1ri75kdj9iqaaedf25kcae481.jpg "/>

This article is from the "Cute Xiaopp" blog, make sure to keep this source http://smartxiaopp.blog.51cto.com/9349053/1575658

Restore border to android4.x version of EditText

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.