Siri Sugunakar
Siri Sugunakar

Reputation: 11

Add border to button image for android

<Button
        android:id="@+id/button_send"
        android:layout_width="150dp"
        android:layout_height="wrap_content"
        android:background="@drawable/buttons"
        android:drawablePadding="10dp"
        android:gravity="left"
        android:padding="15dp"
        android:text="Button"
        android:textColor="#fff"
        android:textSize="15sp" />

Above is my code for Button in My xml file.

My button.xml code is

    <item android:drawable="@drawable/btn_bg_hover"
          android:state_pressed="true" />
    <item android:drawable="@drawable/btn_bg_default"
          android:state_focused="true" />
    <item android:drawable="@drawable/btn_bg_default"/>

kindly help me how to add border to that button.

Note: @drawable/btn_bg_hover is image

Upvotes: 1

Views: 154

Answers (2)

TapanHP
TapanHP

Reputation: 6181

You have to make your custom background drawable file and use it, the stroke property is the one you have to use for making border.
Steps :
Go to res -> drawable -> by right click -> new -> android drawable resource
copy paste this code

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
  android:shape="rectangle">
  <gradient android:startColor="#FFFFFF" 
    android:endColor="#00FF00"
    android:angle="270" />
 <stroke android:width="5px" android:color="#000000" />
</shape>


Here you see the stroke you can change values to make it in your way.

and use it as any components background by

<android:Background ="@drawable/yourCustomBorder.xml"> for example.

Upvotes: 0

thienkhoi tran
thienkhoi tran

Reputation: 341

User stroke tag Android - border for button

<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<gradient android:startColor="#FFFFFF" android:endColor="#00FF00" android:angle="270" />
<corners android:radius="3dp" />
<stroke android:width="5px" android:color="#000000" />

Upvotes: 1

Related Questions