如何在 Android activity 中创建多色形状背景
How to create multi-colored shape background in Android activity
我想将 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>
您需要类似这样的东西作为布局的背景。
<?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>
这在我的模拟器中看起来像这样。
我想将 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>
您需要类似这样的东西作为布局的背景。
<?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>
这在我的模拟器中看起来像这样。