Android 修改EditText的光标颜色和背景色

来源:互联网 发布:算法导论当当 编辑:程序博客网 时间:2024/05/23 18:29

一、EditText的光标颜色

在xml布局文件中 

Android:textCursorDrawable=”@null” 表示光标的颜色和字体的颜色一样

当然,我们也可以自定义光标的颜色,在drawable文件夹下写个edit_cursor_color.xml文件

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <shape xmlns:android="http://schemas.android.com/apk/res/android"
  3.     android:shape="rectangle" >
  4.  
  5.     <size android:width="2dp" />
  6.  
  7.     <solid android:color="#ff7200" />
  8.  
  9. </shape>

然后 android:textCursorDrawable=”@drawable/edit_cursor_color”

二、Edittext 的背景颜色

设置系统的 EditText 是一条下划线,自定义一条下划线的背景色

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
  3.  
  4.     <item>
  5.         <shape android:shape="rectangle" >
  6.             <gradient
  7.                 android:endColor="#ff7200"
  8.                 android:startColor="#ff7200" />
  9.         </shape>
  10.     </item>
  11.     <item android:bottom="2dp">
  12.         <shape android:shape="rectangle" >
  13.             <gradient
  14.                 android:endColor="#eeeeee"
  15.                 android:startColor="#eeeeee" />
  16.         </shape>
  17.     </item>
  18.  
  19. </layer-list>

三、效果

这里写图片描述

 

由于本人初写博客,写的不好的地方还请大家能批评指正,希望能和大家相互学习、相互交流、共同成长。

0 0
原创粉丝点击