Using a gradientDrawable with more than three colors set

前端 未结 5 923
孤独总比滥情好
孤独总比滥情好 2020-12-29 06:40

According to what I\'ve read, you can use a gradientDrawable and have three colors set for it, for example:



        
5条回答
  •  醉梦人生
    2020-12-29 07:21

    It is not possible to do into a xml file, but you can apply +3 color gradient in yout java code with GradientDrawable class:

    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);
    

提交回复
热议问题