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

房东的猫 提交于 2019-12-12 02:31:42

问题


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.


回答1:


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>



来源:https://stackoverflow.com/questions/41893512/android-how-to-create-shape-with-skewed-two-tone-color

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!