2012-02-10 216 views

回答

82

创建一个XML文件中可绘制(说backwithborder.xml)以下:

<shape xmlns:android="http://schemas.android.com/apk/res/android" 
    android:shape="rectangle"> 
    <solid android:color="#00000000" /> 
    <stroke android:width="1dip" android:color="#ffffff" /> 
</shape> 

,为用户的EditText属性的android:背景= “@绘制/ backwithborder”

1

你可以用背景色创建一个线性布局,您想要边框的颜色应该是。然后将编辑文本放入此Linearlayout并给出一些背景颜色。例如:如果边框是灰色的,则Linearview的背景为灰色。 并编辑文本背景黑色。

对于边框宽度,您可以给padding = "1dp"border_width = "1dp"

2

当用户关注它时,Android操作系统本身会为EditText添加边框。颜色取决于操作系统版本。有时我们可能想要摆脱默认的焦点边框,并且有办法做到这一点。

我们可以保持背景颜色为透明以去除焦点上的EditText边框。

 <EditText 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:background="#00000000" 
     /> 
+2

问题是关于未聚焦的状态,而不是聚焦的状态。 – nyi 2014-11-25 17:28:18