Reputation: 6246
I have this drawable I'm using for a 2 button like so
<Button
android:layout_width="0dp"
android:layout_weight="1"
tools:text="No"
android:layout_height="wrap_content"
android:id="@+id/dialog_negative"
android:background="@drawable/btn_trans_blue"
android:textAlignment="gravity"
android:gravity="center"
/>
<Button
android:layout_width="0dp"
android:layout_weight="1"
tools:text="Yes"
android:layout_height="wrap_content"
android:id="@+id/dialog_positive"
android:background="@drawable/btn_trans_blue"
android:textAlignment="gravity"
android:gravity="center"
/>
btn_trans_blue.xml
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_pressed="true"
android:drawable="@color/fublue" />
<item
android:state_activated="true"
android:drawable="@color/fublue" />
<item
android:drawable="@drawable/custom_button" />
</selector>
custom_button.xml
<?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="#FF0000" />
</shape>
</item>
<item android:right="1dp">
<shape android:shape="rectangle">
<solid android:color="@color/white" />
</shape>
</item>
</layer-list>
And what I need is both buttons to have a 1dp border on the top (which that gives), but the negative button to have a 1dp border on the right.
How can I add this to the layout?
Upvotes: 2
Views: 1133
Reputation: 21062
You can replace the border with another shape thats painted below the body color and then add an offset for the top shape only on the sides you want borders. For instance to have a red border only on top, you can do something like this:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<!-- Border -->
<item>
<shape>
<solid android:color="#f000"></solid>
</shape>
</item>
<!-- Body -->
<item android:top="2dp">
<shape>
<solid android:color="#ffafafaf"></solid>
</shape>
</item>
</layer-list>
Or if you need a border (with dashed or whatever) set that border on the first item (the one that will be below) and then the offset on the second item (the one on top) will reveal that border.
Upvotes: 1