简体   繁体   English

如何在Android中为形状设置渐变颜色

[英]How to set gradiant color for stroke in shape in Android

I want create custom background and i want create this in drawable folder. 我想创建自定义背景,我想在drawable文件夹中创建它。
For this background i write below codes : 对于这个背景,我写下面的代码:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">

    <stroke
        android:width="1dp"
        android:color="@color/gradient_center" />

    <corners android:radius="5dp" />

</shape>

but in this code i just set sold color for stroke , i want set gradient color for stroke color. 但在这段代码中,我只设置了stroke 色,我想为stroke颜色设置渐变色。

how can i it? 我怎么样?

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">

<gradient
    android:angle="90"
    android:endColor="#b5b6d2"
    android:startColor="#555994"
    android:type="linear" />

<corners android:radius="5dp" />

</shape>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 以编程方式创建形状背景时,如何使用android.graphics.Color设置笔触颜色? - When creating shape background programmatically, how to set stroke color using android.graphics.Color? Android XML中的渐变自定义形状 - Gradiant Custom Shape in Android XML 在Java中设置形状的笔触宽度和颜色 - Set stroke width and color of a shape in java 颜色状态列表不适用于笔触-Android - Color State List not working for shape stroke - Android 如何在 Android 中以编程方式/动态方式创建此 shape.xml。 设置笔触颜色(包括图片/代码) - How can I create this shape.xml programmatically/dynamically in Android. Set stroke color(pics/code included) Android:如何使用笔触选择器将背景色设置为按钮? - Android: how to set set background color to button using selector with stroke? 如何在不影响描边颜色的情况下从 ImageView 设置形状的填充颜色? - How can you set the fill-color of a shape from an ImageView without affecting the stroke-color? Android:如何以编程方式设置矢量可绘制的笔触颜色 - Android: How to set stroke color for vector drawable programmatically 如何在 android 中为形状制作 3 边的笔划? - how to make stroke for 3 sides for a shape in android? 如何在Android画布上的自定义形状上绘制笔触 - How to draw stroke on custom shape on android canvas
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM