0

I have the following XML drawable to define the different background color for the states of my buttons:

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

How can I add a white border on the right side of my buttons (slightly less in height than the button itself) to act as a divider?

codeman
  • 8,868
  • 13
  • 50
  • 79
  • check this link http://stackoverflow.com/questions/15128652/how-to-add-vertical-divider-to-a-horizontal-linearlayout – Krish Jan 05 '15 at 19:07

1 Answers1

1

Personally, I add a View in the layout of the Activity or Fragment.

    <LinearLayout
        android:orientation="horizontal"
        android:background="@color/my_button_bar_color"
        ... >

        <Button
            ... />

        <View
            android:layout_width="1px"
            android:layout_height="20dp"
            android:gravity="center_vertical"
            android:background="@color/my_button_bar_divider_color" />

        <Button
            ... />

    </LinearLayout>

Alternatively, you can create drawables with the border on the right.

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape android:shape="rectangle">
            <solid android:color="@color/my_border_color" />
        </shape>
    </item>
    <item android:right="1dp">
            <solid android:color="@color/my_main_shape_color" />
    </item>
</layer-list>
TTransmit
  • 3,270
  • 2
  • 28
  • 43