Jain Nidhi
Jain Nidhi

Reputation: 255

Android EditText Border Background Color

In My Application, I have set EditText with border background color and it works fine on all the devices, however on my 4.1.2 devices the whole EditText display as black color. I am able to enter text in it and everything works but text not visible because EditText is completely black in color. If I remove the background border color, it works fine.

here is my xml code for edittext.

<EditText
     android:id="@+id/et_date_from"
     android:layout_width="wrap_content"
     android:layout_height="match_parent"
     android:layout_weight="0.68"
     android:background="@drawable/edittext_border"
     android:ems="10" />

edittext_border.xml

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

    <stroke
        android:width="1dp"
        android:color="@color/test_blue_light" />

    <corners android:radius="5dp" />

</shape>

Please give me any solution.

Upvotes: 1

Views: 4082

Answers (5)

Milad Mohamadi
Milad Mohamadi

Reputation: 135

create xml file in drawable shape_border_and_background_login.xml :

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
       android:shape="rectangle"
    >
    <corners android:radius="25dip" />
    <solid android:color="#55ffffff">

    </solid>
<stroke
    android:width="2dp"
    android:color="@color/white" />

add shape file to EditText background:

 <EditText
                      android:id="@+id/edt_email"
                      android:layout_width="0dp"
                      android:layout_height="wrap_content"
                      android:layout_weight="10"
                    android:background="@drawable/shape_border_and_background_login"
                      android:inputType="textPersonName"
                      android:padding="@dimen/size15"
                      android:textSize="@dimen/size17"
                     />

Upvotes: 0

&#214;zer &#214;zcan
&#214;zer &#214;zcan

Reputation: 1293

if you want to show only border, and set to bg transparent use above code `

<corners
    android:radius="5dp"></corners>

<stroke
    android:width="2px"
    android:color="@color/colorPrimary"></stroke>

<solid android:color="@android:color/transparent"/>

`

Upvotes: 1

Milan Jayawardane
Milan Jayawardane

Reputation: 137

I know this an old question and there's an accepted answer but I want to update @Sajal's answer for people who are having same issue in future. It is good to use 'transparent' as your solid color so it won't effect to current design of your layout.

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

      <stroke
          android:width="1dp"
          android:color="@color/test_blue_light" />
      <solid android:color="@android:color/transparent"/>

      <corners android:radius="5dp" />

   </shape>

Upvotes: 2

Dheeraj Chaudhary
Dheeraj Chaudhary

Reputation: 71

Set solid property to your background(drawable) file.

        <solid color="color according to your need">

Upvotes: 1

Sajal
Sajal

Reputation: 1472

Try this for shape.

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

    <stroke
        android:width="1dp"
        android:color="@color/test_blue_light" />
    <solid android:color="@color/white"/>

    <corners android:radius="5dp" />

</shape>

Upvotes: 9

Related Questions