How to change the border color(un-focused) of an E

2019-01-11 02:59发布

I changed the background color of the EditText to transperant. Now the EditText looks invisible when not focused. So how can I change the un-focused border color of EditText?

What is the XML attribute for this?

4条回答
冷血范
2楼-- · 2019-01-11 03:10

Android OS itself adds border to EditText when user focus on it. The color depends on the OS version. Sometimes we might want to get rid of default focus border and there is a way to do it.

We can keep the background color as transparent to remove the EditText border on focus.

     <EditText 
         android:layout_width="fill_parent"
         android:layout_height="wrap_content"
         android:background="#00000000"
      />
查看更多
Fickle 薄情
4楼-- · 2019-01-11 03:20

You can create a linearlayout with background color the color which you want the border should be. Then place the Edit text inside this Linearlayout and give some background color. Eg : if border is grey then background for Linearview is grey. and edit text background black.

for width of border you can give padding = "1dp" for border_width = "1dp".

查看更多
beautiful°
5楼-- · 2019-01-11 03:26

Create a XML file with the following in drawable (say 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>

and for the EditText user attribute android:background="@drawable/backwithborder"

查看更多
登录 后发表回答