给Android4.X版本的EditText恢复边框

发布时间:2020-06-26 08:37:46 作者:诗和远方abc
来源:网络 阅读:764

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>

效果如图:给Android4.X版本的EditText恢复边框

推荐阅读:
  1. EditText底部边框被软键盘挡住的问题
  2. 如何给布局套上带颜色的边框

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

4.0 android 下划线

上一篇:升级XCode7后,Qt编译无法找到SDK的问题

下一篇:Powershell 管理应用系列(Part2 )

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》