How To Make Bottom Border In Drawable Shape Xml Selector?
I'm trying to create a drawable shape with different states for my button. So I wrote this: -
Solution 1:
First I'm separating the shapes to make them easier to manage.
This is your btn_negative_selector.xml
<?xml version="1.0" encoding="utf-8"?><selectorxmlns:android="http://schemas.android.com/apk/res/android"><itemandroid:drawable="@xml/rectangle_button_pressed"android:state_pressed="true"></item><itemandroid:drawable="@xml/rectangle_button_focused"android:state_focused="true"></item><itemandroid:drawable="@xml/rectangle_button" ></item></selector>
create folder called 'xml' in your res and save these shapes into it:
1) rectangle_button_pressed:
<shapexmlns:android="http://schemas.android.com/apk/res/android"android:shape="rectangle" ><solidandroid:color="@color/NEGATIVE_pressed" /><strokeandroid:width="1dp"android:color="@color/ORANGE" /><cornersandroid:radius="4dp" /></shape>
2) rectangle_button_focused:
<shapexmlns:android="http://schemas.android.com/apk/res/android"android:shape="rectangle" ><solidandroid:color="@color/NEGATIVE_focused" /><strokeandroid:width="1dp"android:color="@color/ORANGE" /><cornersandroid:radius="4dp" /></shape>
3) This one rectangle_button.xml will have a border at the bottom of it by defining a shape using <layer-list>.
first <item>
is bottom layer and last <item>
is the top layer.
<?xml version="1.0" encoding="UTF-8"?><layer-listxmlns:android="http://schemas.android.com/apk/res/android" ><item><shapeandroid:shape="rectangle"><solidandroid:color="@color/gray"/><cornersandroid:radius="4dp"/></shape></item><itemandroid:bottom="3dp"><shapeandroid:shape="rectangle"><solidandroid:color="@color/orange" /><cornersandroid:radius="4dp"/></shape></item></layer-list>
Post a Comment for "How To Make Bottom Border In Drawable Shape Xml Selector?"