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

    转载自:点击打开链接

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

    [html] view plaincopy
     
     
     
    1. <EditText   
    2.     android:layout_width="fill_parent"  
    3.         android:layout_height="36dip"  
    4.         android:background="@drawable/bg_edittext"  
    5.         android:padding="5dip"  
    6.     android:layout_margin="36dip"  
    7.     android:textColorHint="#AAAAAA"  
    8.     android:textSize="15dip"  
    9.     android:singleLine="true"  
    10.     android:hint="请输入..."  
    11. />  


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

    bg_edittext_normal.xml(未获得焦点时)

    [html] view plaincopy
     
     
     
    1. <?xml version="1.0" encoding="UTF-8"?>   
    2. <shape xmlns:android="http://schemas.android.com/apk/res/android">   
    3.     <solid android:color="#FFFFFF" />   
    4.     <corners android:radius="3dip"/>  
    5.     <stroke    
    6.         android:width="1dip"    
    7.         android:color="#BDC7D8" />   
    8. </shape>  

    bg_edittext_focused.xml(获得焦点时)

    [html] view plaincopy
     
     
     
    1. <?xml version="1.0" encoding="UTF-8"?>   
    2. <shape xmlns:android="http://schemas.android.com/apk/res/android">   
    3.     <solid android:color="#FFFFFF" />   
    4.     <corners android:radius="3dip"/>  
    5.     <stroke    
    6.         android:width="1dip"    
    7.         android:color="#728ea3" />   
    8. </shape>  

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

    [html] view plaincopy
     
     
     
    1. <?xml version="1.0" encoding="UTF-8"?>   
    2. <selector xmlns:android="http://schemas.android.com/apk/res/android">  
    3.         <item android:state_window_focused="false" android:drawable="@drawable/contact_edit_edittext_normal" />  
    4.        <item android:state_focused="true" android:drawable="@drawable/contact_edit_edittext_focused" />  
    5. </selector>  


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

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

    路漫漫其修远兮 吾将上下而求索
  • 相关阅读:
    luogu P1833 樱花 看成混合背包
    luogu P1077 摆花 基础记数dp
    luogu P1095 守望者的逃离 经典dp
    Even Subset Sum Problem CodeForces
    Maximum White Subtree CodeForces
    Sleeping Schedule CodeForces
    Bombs CodeForces
    病毒侵袭持续中 HDU
    病毒侵袭 HDU
    Educational Codeforces Round 35 (Rated for Div. 2)
  • 原文地址:https://www.cnblogs.com/hudabing/p/3780506.html
Copyright © 2011-2022 走看看