0

I have an XML file called playnext. I added this file as a background to my button.XML include two images that is for button press and button release.I need to add border to these two images using the XML.

XML code

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="false" android:drawable="@drawable/ic_remote_playnext" ></item>
    <item android:state_pressed="true" android:drawable="@drawable/next_pressdown" ></item>
</selector>

Please tell me how to add a border to this? Is there is any other way to add borders to button?

Nuwan Indika
  • 901
  • 4
  • 14
  • 27

2 Answers2

3

make a drawable xml as selector

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" >
    <shape>
        <solid
            android:color="yoursolidcolor for state pressed" />
        <stroke
            android:width="1dp"
            android:color="#171717" />
        <corners
            android:radius="3dp" />
        <padding
            android:left="5dp"
            android:top="5dp"
            android:right="5dp"
            android:bottom="5dp" />
    </shape>
</item>
<item>
    <shape>
        <solid
            android:color="#yoursolidcolor for default" />
        <stroke
            android:width="0dp"
            android:color="#171717" />
        <corners
            android:radius="4dp" />
        <padding
            android:left="5dp"
            android:top="5dp"
            android:right="5dp"
            android:bottom="5dp" />
    </shape>
</item>
</selector>

Then

<Button 
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@drawable/youraboveselectoe"
    android:textColor="@color/white"
    android:text="Button"/>

you can also check on this

Is it possible to specify border in android button?

Community
  • 1
  • 1
Shadik Khan
  • 1,217
  • 1
  • 8
  • 18
0

Please add the following code in drawable xml and call the this xml like using

         android:background="@drawable/border"

border.xml

 <selector xmlns:android="http://schemas.android.com/apk/res/android" android:exitFad   eDuration="@integer/short_anim_time">

<item android:drawable="@color/orange" android:state_pressed="true" />



<item android:drawable="@color/white" android:state_focused="true" />

<item android:drawable="@color/white" />

<item>
    <shape>
        <stroke android:width="2dp" android:color="@color/orange" />

        <padding android:bottom="@dimen/gap" android:left="@dimen/gap" android:right="@dimen/gap" android:top="@dimen/gap" />
    </shape>
</item>

Rahul Karande
  • 259
  • 2
  • 9