1

I got some code but not perfact-

<shape xmlns:android="http://schemas.android.com/apk/res/android" 
       android:thickness="0dp" 
       android:shape="rectangle">

  <stroke android:width="2dp"
         android:color="#00cc33"/>

</shape>

it gives border color but background color is black. Thank's in advance...

Ashish Kumar
  • 113
  • 1
  • 4
  • 10
  • 1
    possible duplicate of [custom designing a edittext](http://stackoverflow.com/questions/19189265/custom-designing-a-edittext) – Maveňツ Nov 21 '14 at 12:37
  • https://stackoverflow.com/questions/3496269/how-do-i-put-a-border-around-an-android-textview?rq=1 – live-love Mar 12 '18 at 23:35

5 Answers5

5

Use this selector as background for your EditText

<shape xmlns:android="http://schemas.android.com/apk/res/android" 
       android:thickness="0dp" 
       android:shape="rectangle">
 <solid android:color="#FFFFFF" />
  <stroke android:width="2dp"
         android:color="#00cc33"/>

</shape>
MathanG
  • 1,135
  • 9
  • 19
1

*

`Use  android:background="@drawable/rounded_edittext" in your editext layout
          and make a rounded_edittext in your drawable folder of your project** 
           <shape xmlns:android="http://schemas.android.com/apk/res/android"
            android:shape="rectangle" android:padding="5dp">
             <solid android:color="#ffffff"/>
             <stroke
                    android:width="2dp"
                    android:color="#13a7c1" />
                <corners
                 android:bottomRightRadius="15dp"
                 android:bottomLeftRadius="15dp"
                  android:topLeftRadius="15dp"
                android:topRightRadius="15dp"/>
              </shape>`    *

*

Pradeep Sodhi
  • 2,110
  • 1
  • 17
  • 19
0

For givin the background color, use "solid":

       <shape xmlns:android="http://schemas.android.com/apk/res/android" 
   android:thickness="0dp" 
   android:shape="rectangle">

       <stroke android:width="2dp"
     android:color="#00cc33"/>
        <solid
     android:color="#ffffff"/>

   </shape>
Opiatefuchs
  • 9,455
  • 2
  • 30
  • 47
0

try this, custom_border.xml

<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >

<item>
    <shape android:shape="rectangle" >
        <solid android:color="#000000" />
    </shape>
</item>
<item
    android:left="1dp"
    android:right="1dp"
    android:top="1dp"
    android:bottom="1dp">
    <shape android:shape="rectangle" >
        <solid android:color="#FFFFFF" />
    </shape>
</item>

then set it to your editext background.

0

Create an xml say edit_text_background.xml in res/drawable folder..

and add the following cod to it...

 <shape xmlns:android="http://schemas.android.com/apk/res/android"
 android:shape="rectangle">

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

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

        <stroke android:color="@color/black" android:width="3dp"/>

        <padding android:left="5dp" android:top="5dp" android:right="5dp" android:bottom="5dp"/>

</shape>

stroke : to apply border. solid : to apply background color corners : to apply radius at corners(if you want)

set this xml as background to edittext

android:background="@drawable/edit_text_background"

Hope it works..!

iMDroid
  • 2,023
  • 1
  • 13
  • 29