【问题标题】:How to create multi-colored shape background in Android activity如何在 Android 活动中创建多色形状背景
【发布时间】:2017-09-29 19:33:34
【问题描述】:

我希望将我的Activity 的背景设置为两种颜色。顶部为自定义颜色,底部为白色。问题是我不想用水平线将它们分开。我想创建与提供的图像非常相似的东西。我真的不知道从哪里开始创建这个......

我试过了,但我真的不想水平分离。我希望分离更像图像。

这是我迄今为止尝试过的。

<?xml version="1.0" encoding="UTF-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape android:shape="rectangle">
            <solid android:color="#FAFAFA" />
        </shape>
    </item>
    <item android:bottom="300dp" android:top="0dp" android:left="0dp" android:right="0dp">
        <shape android:shape="rectangle">
            <solid android:color="@color/colorPrimary" />
        </shape>
    </item>
</layer-list>

【问题讨论】:

标签: android xml-drawable


【解决方案1】:

您需要这样的东西作为布局的背景。

<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
    android:width="100dp"
    android:height="100dp"
    android:viewportHeight="100"
    android:viewportWidth="100">
    <path
        android:fillColor="@color/colorPrimary"
        android:pathData="M0,0 L0,50 L500,80 L500,0 z" />
</vector>

这在我的模拟器中看起来像这样。

【讨论】:

    猜你喜欢
    • 2015-04-19
    • 2017-09-03
    • 2020-08-08
    • 2015-05-19
    • 2019-12-21
    • 1970-01-01
    • 1970-01-01
    • 2021-01-25
    • 1970-01-01
    相关资源
    最近更新 更多