简体   繁体   中英

How to set the Top Stroke of Button?

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>

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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM