zoukankan      html  css  js  c++  java
  • Android EditText 改变边框颜色

    第一步:为了更好的比较,准备两个一模一样的EditText(当Activity启动时,焦点会在第一个EditText上,如果你不希望这样只需要写一个高度和宽带为0的EditText即可避免,这里就不这么做了),代码如下:

    <EditText 
        android:layout_width="fill_parent"
        android:layout_height="36dip"
        android:background="@drawable/bg_edittext"
        android:padding="5dip"
        android:layout_margin="36dip"
        android:textColorHint="#AAAAAA"
        android:textSize="15dip"
        android:singleLine="true"
        android:hint="请输入..."
    />

    接下来建立三个xml文件,分别为输入框未获得焦点时的背景,输入框获得焦点时的背景,selector背景选择器(这里能获得输入框什么时候获得和失去焦点),代码如下:

    bg_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>

    bg_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>

    bg_edittext.xml(selector选择器,这方面资料网上很多)

    <?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/contact_edit_edittext_normal" />
           <item android:state_focused="true" android:drawable="@drawable/contact_edit_edittext_focused" />
    </selector>

    这样就OK了,效果图如下:

    第二个输入框边框变为深色,是不是这样更友好点。

  • 相关阅读:
    JS小白进阶之路(2)
    JS小白进阶之路(1)
    ajax.readyState与ajax.status一览
    Photoshop投影和CSS box-shadow转换
    layer弹层插件
    [Intervention] Ignored attempt to cancel a touchmove event with cancelable=false, for example because scrolling is in progress and cannot be interrupted
    css清除浮动影响
    css网页重置样式表(多版本)
    XSS攻击和CSRF攻击的定义及区别
    git的cd命令
  • 原文地址:https://www.cnblogs.com/zhujiabin/p/6208053.html
Copyright © 2011-2022 走看看