您的位置:首页 > 移动开发 > Android开发

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

2016-04-14 15:47 267 查看

Edittext 的光标颜色:

在xml布局文件中

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

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

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >

<size android:width="2dp" />

<solid android:color="#ff7200" />

</shape>


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



Edittext 的背景颜色:

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

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >

<item>
<shape android:shape="rectangle" >
<gradient
android:endColor="#ff7200"
android:startColor="#ff7200" />
</shape>
</item>
<item android:bottom="2dp">
<shape android:shape="rectangle" >
<gradient
android:endColor="#eeeeee"
android:startColor="#eeeeee" />
</shape>
</item>

</layer-list>


效果完全就是上图效果。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: