简体   繁体   中英

Drawable android to make top edge rounded with different color

How to make top-left with light gray rounded color and top-right with dark gray and bottom-edges with white rounded,

Currently i am getting bottom-edges white rounded but want to change the color of top left and right rounded with different color.

I tried :

<?xml version="1.0" encoding="utf-8"?>


<selector xmlns:android="http://schemas.android.com/apk/res/android" >

    <item >
        <shape android:shape="rectangle"  >
            <corners android:bottomLeftRadius="3dip"
                android:bottomRightRadius="3dip"
                android:topRightRadius="3dip"
                android:topLeftRadius="3dip"
                />
            <stroke android:width="1dip" android:color="@color/white" />
            <gradient android:angle="-90" android:startColor="@color/white" android:endColor="@color/white" />
        </shape>

    </item>
</selector>

Image Link :

1: Define layout_bg.xml in drawables:

<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#FFFFFF"/>
<stroke android:width="3dip" android:color="#B1BCBE" />
<corners android:radius="10dip"/>
<padding android:left="0dip" android:top="0dip" android:right="0dip"       
 android:bottom="0dip"/>
</shape>

2: Add layout_bg.xml as background to your layout

android:background="@drawable/layout_bg"

Try this code..I hope you useful

Try this :

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape>
            <solid android:color="#959595" />
            <stroke
                android:width="0dp"
                android:color="#959595" />
            <corners android:radius="3dp" />
            <gradient
                android:angle="0"
                android:endColor="@android:color/black"
                android:startColor="@android:color/darker_gray" />
            <padding
                android:bottom="0dp"
                android:left="3dp"
                android:right="3dp"
                android:top="3dp" />
        </shape>
    </item>

    <item>
        <shape>

            <solid android:color="#FFFFFF" />
            <stroke
                android:width="0dp"
                android:color="#FFFFFF" />
            <corners
                android:topLeftRadius="3dp"
                android:topRightRadius="3dp" />
            <padding
                android:bottom="3dp"
                android:left="0dp"
                android:right="0dp"
                android:top="0dp" />
        </shape>
    </item>


    <item>
        <shape>
            <solid android:color="#FFFFFF" />
            <stroke
                android:width="0dp"
                android:color="#c2c2c2" />
            <corners
                android:radius="3dp"
                />
            <padding
                android:bottom="3dp"
                android:left="0dp"
                android:right="0dp"
                android:top="0dp" />
        </shape>
    </item>

</layer-list>

if you want something like this 在此处输入图片说明

then follow my code test.xml

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape>
            <solid android:color="#959595" />
            <stroke
                android:width="0dp"
                android:color="#959595" />
            <corners android:radius="3dp" />
            <gradient
                android:angle="-90"
                android:endColor="@android:color/black"
                android:startColor="@android:color/darker_gray" />
            <padding
                android:bottom="3dp"
                android:left="3dp"
                android:right="3dp"
                android:top="3dp" />
        </shape>
    </item>
    <item >
        <shape android:shape="rectangle"
            >
            <solid android:color="#fff" />
        </shape>
    </item>
</layer-list>

I applied my drwable to a textview background

<TextView
    android:layout_width="200dp"
    android:layout_height="200dp"
    android:layout_gravity="center"
    android:background="@drawable/test"
    android:padding="10dp"
    android:text="@string/hello_blank_fragment" />

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