Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set the Top Stroke of Button?

Tags:

android

layout

My question is really simple. That is about Button attrs. I want to make Button which has only Top stoke. What can I set in layout xml ??

My xml file is

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_enabled="false">
        <shape>
            <solid android:color="@android:color/transparent"/>
            <stroke android:width="1dp" android:color="@color/btn_disable"
                    android:dashWidth="1dp" android:dashGap="0dp"/>
            <padding android:left="9dp" android:top="2dp"
                     android:right="9dp" android:bottom="2dp"/>
            <corners android:radius="@dimen/btn_radius" />
        </shape>
    </item>
    <item android:state_pressed="true" >
        <shape>
            <solid android:color="@color/white_pressed"/>
            <stroke android:width="1dp" android:color="@color/mint"
                    android:dashWidth="1dp" android:dashGap="0dp"/>
            <padding android:left="9dp" android:top="2dp"
                     android:right="9dp" android:bottom="2dp"/>
            <corners android:radius="@dimen/btn_radius" />
        </shape>
          </item>
    <item>
        <shape>
            <solid android:color="@null"/>
            <stroke android:width="1dp" android:color="@color/mint"
                    android:dashWidth="1dp" android:dashGap="0dp" />
            <corners android:radius="@dimen/btn_radius" />
        </shape>
    </item>
</selector>
like image 299
kimkevin Avatar asked Nov 23 '25 10:11

kimkevin


1 Answers

I cannot determine the exact shape you are looking for, but judging that you only want the top stroke, hide all other strokes, you can use a layer-list to achieve this.

<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
    <item>
        <shape android:shape="rectangle">

            <solid android:color="your_stroke_colour" />

            <corners
                android:radius="your_radius" />

        </shape>
    </item>
    <item
        android:top="1dp"
        android:bottom="0dp"
        android:left="0dp"
        android:right="0dp">
        <shape android:shape="rectangle">

            <solid android:color="your_color" />

            <corners
                android:radius="your_radius" />

        </shape>
    </item>
</layer-list>
like image 106
jyoonPro Avatar answered Nov 25 '25 00:11

jyoonPro



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!