Android4.0以后的版本的EditText的新特征是以单下划线的形式出现,但是很多时候我们需要加上边框看起来比较美观.下面请看具体操作:
分为两部分:未输入文本时的状态(normal)和点击输入文本的状态(focused).
下面是EditText的控件:
<EditText
android:layout_width="fill_parent"
android:layout_height="36dip"
android:background="@drawable/edittext"
android:padding="5dip"
android:layout_margin="36dip"
android:textColorHint="#AAAAAA"
android:textSize="15dip"
android:hint="@string/asdasd_"
android:singleLine="true" />
其中android:background="@drawable/edittext" 是另外定义的edittext.xml选择器(存放在drawable任意文件夹下)下面定义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>
接着就是定义edittext_normal.xml和edittext_focused.xml文件,具体如下:
edittext_normal.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="#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>
效果如图:
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。