---
title: "android 中 EditText加入图标 更改边框颜色 设置透明 代码 "
author: "hack_zhang"
date: "2013-07-19T10:20:38Z"
tags: []
categories: ["移动开发"]
slug: "android-edittext"
draft: false
lastmod: "2013-07-19T10:20:38Z"
id: 1910021
url: "https://hack-zhang.iteye.com/blog/1910021"
---

main.xml

**\[java]** [view plain](http://blog.csdn.net/liushengmeng/article/details/8121394 "view plain")[copy](http://blog.csdn.net/liushengmeng/article/details/8121394 "copy")

01. &lt;?xml version="1.0" encoding="utf-8"?&gt;
02. &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
03. android:layout\_width="fill\_parent"
04. android:layout\_height="fill\_parent"
05. android:background="@drawable/bg"
06. android:orientation="vertical" &gt;
07. &lt;EditText
08. android:id="@+id/et"
09. android:layout\_width="251dp"
10. android:layout\_height="wrap\_content"
11. android:layout\_gravity="center"
12. android:drawableLeft="@drawable/title"
13. android:background="@drawable/shape"
14. android:padding="10px"
15. android:hint="北京"
16. android:singleLine="true"
17. android:textColor="#FFFAFA"/&gt;
18. &lt;/LinearLayout&gt;

 

在drawable中建一个xml文件：shape.xml

 

**\[java]** [view plain](http://blog.csdn.net/liushengmeng/article/details/8121394 "view plain")[copy](http://blog.csdn.net/liushengmeng/article/details/8121394 "copy")

1. &lt;?xml version="1.0" encoding="utf-8"?&gt;
2. &lt;shape xmlns:android="http://schemas.android.com/apk/res/android"&gt;
3. &lt;solid android:color="#00ff00ff"/&gt;
4. &lt;corners android:radius="8px"/&gt;
5. &lt;stroke android:color="#32CD32"
6. android:width="2px"
7. /&gt;
8. &lt;/shape&gt;

 

![](http://img.my.csdn.net/uploads/201210/28/1351416038_8948.jpg)