Lord Goderick
Lord Goderick

Reputation: 985

Android: how to create shape with skewed two-tone color?

I am attempting to create a drawable shape that will become the background of a search bar. I know how to create a rectangle with two colors but I do not know how to tilt the color at an angle, like in the second image. Can someone help me with this? Thanks.

enter image description here

Upvotes: 0

Views: 1428

Answers (1)

Arnab Kundu
Arnab Kundu

Reputation: 1527

Take a Toolbar...code is here...

 <android.support.v7.widget.Toolbar
    android:layout_width="500dp"
    android:layout_height="wrap_content"
    android:background="@drawable/custom_background" />

create a drawable res file custom_background.xml and

In that toolbar set drawable like this....code is here

<?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="500dp"
            android:height="50dp" />
        <solid android:color="#0072BC" />
        <corners android:radius="0dp"/>
    </shape>
</item>

<item
    android:top="8dp"
    android:bottom="0dp"
    android:left="-400dp"
    android:right="128dp">
    <rotate
        android:fromDegrees="160">
        <shape android:shape="rectangle">
            <solid android:color="#FFF" />
        </shape>
    </rotate>
</item>

Upvotes: 3

Related Questions