EditText添加边框

时间:2014-05-03 15:00:05   收藏:0   阅读:328

首先准备两张图片,一张是EditText获得焦点后的边框背景,一张是没有获得焦点时的背景,注意制作成9.png样式的图片,然后在drawable里添加一个selector_edittext_bg.xml文件,内容如下:

<?xml version="1.0" encoding="utf-8"?><selectorxmlns:android="http://schemas.android.com/apk/res/android"><itemandroid:drawable="@drawable/edit_pressed"android:state_focused="true"/><itemandroid:drawable="@drawable/edit_normal"/></selector>

然后在values文件夹下新建一个style.xml文件,内容如下:

<?xml version="1.0" encoding="utf-8"?><resources><stylename="my_edittext_style"parent="@android:style/Widget.EditText"><itemname="android:background">@drawable/selector_edittext_bg</item></style></resources>

最后在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=""/>


EditText添加边框,布布扣,bubuko.com

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!