我需要制作一个自定义矩形,该矩形应使用从 #bff54a 到 #88c010 的十六进制颜色。
实际上我有这个 xml,但我只能使用其中一种颜色。我怎样才能使渐变成为可能?我已经搜索过,但没有找到类似的内容。
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<stroke
android:width="1dp"
android:color="@color/gray_light" />
<solid android:color="#88c010" />
<corners
android:bottomLeftRadius="8dp"
android:bottomRightRadius="8dp"
android:topLeftRadius="8dp"
android:topRightRadius="8dp" />
</shape>
谢谢大家!
最佳答案
使用渐变作为可绘制对象的颜色:
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<stroke
android:width="1dp"
android:color="@color/gray_light" />
<gradient
android:type="linear"
android:centerX="0"
android:centerY="1"
android:startColor="#bff54a"
android:endColor="#88c010" />
<corners
android:bottomLeftRadius="8dp"
android:bottomRightRadius="8dp"
android:topLeftRadius="8dp"
android:topRightRadius="8dp" />
</shape>
关于java - Android 形状矩形有 2 种颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27514466/