User
User

Reputation: 722

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

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

Upvotes: 1

Views: 761

Answers (5)

Rathiga Jesika
Rathiga Jesika

Reputation: 357

<?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.

Upvotes: 0

Nitin Singh
Nitin Singh

Reputation: 143

<?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>

Upvotes: 1

Tulsi
Tulsi

Reputation: 719

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> 

Upvotes: 1

Shailendra Kushwah
Shailendra Kushwah

Reputation: 415

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"/>

Upvotes: 0

AJay
AJay

Reputation: 1193

Hello try below code with replace your stroke

<stroke android:width="1dip"
        android:color="**your color goes here**"/>

Upvotes: 3

Related Questions