Krishnaraj
Krishnaraj

Reputation: 2420

Android Shape - Square with Circle and Different Top Color

I am trying to create a shape drawable like below.

enter image description here

where only the top left section is in different color ( here white ). Thought placing a rectangle with smaller size would let me achieve this but I was wrong. Am I even going in the right direction?

Here's my drawable.xml file.

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
    <shape android:shape="rectangle">
        <size android:width="15dp" android:height="15dp"/>
        <solid android:color="@android:color/white" />
    </shape>
</item>
<item>
    <shape android:shape="oval">
        <solid android:color="@android:color/black" />
    </shape>
</item>
</layer-list>

Upvotes: 1

Views: 6751

Answers (1)

Amarjit
Amarjit

Reputation: 4357

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape android:shape="rectangle">
            <size android:width="60dp" android:height="60dp"/>
            <solid android:color="@android:color/white" />
        </shape>
    </item>



    <item android:left="40dp">
        <shape android:shape="rectangle">
            <size android:width="30dp" android:height="30dp"/>
            <solid android:color="#ff0000" />
        </shape>
    </item>

    <item android:top="30dp" android:bottom="0dip">
        <shape android:shape="rectangle">
            <size android:width="10dp" android:height="10dp"/>
            <solid android:color="#ff0000" />
        </shape>
    </item>

    <item>
    <shape android:shape="oval">
        <stroke android:color="@android:color/black" android:width="1dp"/>
        <size android:width="60dp" android:height="60dp"/>
        <solid android:color="#ff0000" />
    </shape>
</item>

</layer-list>

Upvotes: 4

Related Questions