我们可以在xml中为android背景制作多个颜色渐变吗?

我一直在尝试在XML中创建多色背景,但只有3个选项可用,包括开始,中间,结束和指定的角度。 我们不能让这样的背景下面.. 多颜色在不同的角度

多颜色在不同的角度

我们可以在android中像这样的背景?

根据developers.android你可以…这是他们使用的代码

     

这里也是一个教程

希望这可以帮助

您不能在xml文件中实现+3渐变颜色。 但是你可以使用GradientDrawable类来实现你的java / kotlin代码。 这是Java版本,用你的颜色ID替换颜色数组。

 GradientDrawable gradientDrawable = new GradientDrawable( Orientation.TOP_BOTTOM, new int[]{ContextCompat.getColor(this, R.color.color1), ContextCompat.getColor(this, R.color.color2), ContextCompat.getColor(this, R.color.color3), ContextCompat.getColor(this, R.color.color4)}); findViewById(R.id.background).setBackground(gradientDrawable); 

你可以使用径向渐变图层列表,然后为不同的项目设置不同的不透明度