how to change boundary color of a custom shape in android?

Question

I am creating an edit text with rounded corners, for which i am using a custom shape and assiging it to edit text. I want: 1- Filled area of edit text to be white. 2- Boundary of edit text should be green. the first requirement is fulfilled but i am unable to do the second one. how this can be achieved? any help will be appreciated Here is my code Edit text code:

<EditText
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:hint="E-mailadres"
        android:background="@drawable/rounded_layout"
        android:layout_marginTop="8dp"
        android:layout_weight="2"/>

Custom layout:

   <?xml version="1.0" encoding="utf-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle" android:padding="10dp"
    >
    <solid android:color="#FFFFFF"/>
    <corners
        android:bottomRightRadius="10dp"
        android:bottomLeftRadius="10dp"
        android:topLeftRadius="10dp"
        android:topRightRadius="10dp"
        />
    <stroke android:width="1dip"  />
</shape>

Image of required output: enter image description here


Show source
| android   | xml   | android-edittext   2017-01-03 06:01 5 Answers

Answers ( 5 )

  1. 2017-01-03 06:01

    Hello try below code with replace your stroke

    <stroke android:width="1dip"
            android:color="**your color goes here**"/>
    
  2. 2017-01-03 06:01

    Create an XML file put and it into drawable folder

    <?xml version="1.0" encoding="utf-8" ?>
    
    <shape xmlns:android="http://schemas.android.com/apk/res/android"
           android:thickness="0dp"
           android:shape="rectangle">
      <stroke android:width="3dp"
             android:color="#4799E8"/>
      <corners android:radius="5dp" />
      <gradient
       android:startColor="#C8C8C8"
       android:endColor="#FFFFFF"
       android:type="linear"
       android:angle="270"/>
    </shape>
    

    and Edittext code like this

    <EditText
                android:id="@+id/inputSearchEditText"
                android:layout_marginLeft="15dp"
                android:layout_marginTop="15dp"
                android:layout_marginBottom="20dp"
                android:layout_marginRight="15dp"
                android:layout_centerVertical="true"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:ellipsize="start"
                android:gravity="center"
                android:hint="Search text"
                android:inputType="text"
                android:background="@drawable/EditTextStyle"/>
    
  3. 2017-01-03 06:01
    <?xml version="1.0" encoding="utf-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <stroke android:width="1dp"
        android:color="#04B404" />
    <corners
        android:radius="3dp"/>
    <solid android:color="#FFFFFF"/>
    </shape>
    

    add this in your drawable xml. and set this as background of your edittext.

  4. 2017-01-03 06:01

    You need to add stroke to your to your drawable file.

    Replace code with this

    <?xml version="1.0" encoding="utf-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android"
        android:shape="rectangle" android:padding="10dp">
        <solid android:color="#FFFFFF"/>
        <corners
            android:bottomRightRadius="10dp"
            android:bottomLeftRadius="10dp"
            android:topLeftRadius="10dp"
            android:topRightRadius="10dp"
            />
        <stroke android:width="1dip" android:color="#0075cb"  />
    </shape> 
    
  5. 2017-01-03 06:01
    <?xml version="1.0" encoding="utf-8"?>
    <shape
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:shape="rectangle">
        <stroke android:width="3dp" android:color="#8bc34a" />
        <corners android:radius="10dip"/>
        <gradient
            android:startColor="#ffffff"
            android:endColor="#ffffff"
            />
    </shape>
    
◀ Go back