2

I have a drawable (xml) like this.

<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<corners android:radius="10dp"/>
<padding android:left="5dp" android:right="5dp" android:top="5dp" android:bottom="5dp"/>
<solid android:color="#FF00FF00"/>
</shape>

My button is within a parent linear layout.

<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center_horizontal"
    android:background="@drawable/custombordergreen"
    android:orientation="vertical">

    <Button
        android:id="@+id/startClock"
        style="?android:attr/buttonStyleSmall"
        android:layout_width="204dp"
        android:layout_height="66dp"
         android:text="@string/start"
        android:textSize="22sp"
        android:layout_gravity="center_horizontal"
        android:background="@drawable/startbutton"/>

</LinearLayout>

But I can't use that technique if the button is already a sibling (and referenced in "toLeftOf") in a relative layout.

Short of re working the layout to avoid "relative", is there another way to put a border around my button?

BryanT
  • 412
  • 3
  • 12

2 Answers2

5

put this as your button background

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
  android:shape="rectangle" >

 <solid android:color="#ff3399" />

<stroke
    android:width="0.5dp"
    android:color="#111111" />

<corners
    android:bottomLeftRadius="05dp"
    android:bottomRightRadius="05dp"
    android:topLeftRadius="05dp"
    android:topRightRadius="05dp" />
</shape>
Gopal Singh
  • 1,133
  • 1
  • 9
  • 25
  • 1
    That worked fine. I can make it look just like those from my first solution. I will change all my buttons, for consistency. – BryanT Jan 28 '16 at 17:28
0

Change your solid android:color in xml

<solid android:color="#00000000" />
Pitty
  • 1,907
  • 5
  • 16
  • 34
  • I don't think that will help. The colours are what I want when used in a linear layout. I get an error when the linear layout containing only the button is "wrapped" by a relative layout which refers to my button. – BryanT Jan 28 '16 at 12:52