Android:如何用偏斜的两个色调创建形状? [英] Android: how to create shape with skewed two-tone color?

查看:99
本文介绍了Android:如何用偏斜的两个色调创建形状?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个可绘制的形状,该形状将成为搜索栏的背景。我知道如何创建具有两种颜色的矩形,但是不知道如何像第二幅图像那样以一定角度倾斜颜色。有人可以帮我弄这个吗?谢谢。

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.

推荐答案

使用工具栏...代码在这里...

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" />

创建一个可绘制的res文件custom_background.xml和

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>

这篇关于Android:如何用偏斜的两个色调创建形状?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆