Android LinearLayout Gradient Background

前端 未结 10 1803
渐次进展
渐次进展 2020-12-02 04:20

I am having trouble applying a gradient background to a LinearLayout.

This should be relatively simple from what I have read but it just doesn\'t seem to work. For r

10条回答
  •  猫巷女王i
    2020-12-02 04:33

    With Kotlin you can do that in just 2 lines

    Change color values in the array

                      val gradientDrawable = GradientDrawable(
                            GradientDrawable.Orientation.TOP_BOTTOM,
                            intArrayOf(Color.parseColor("#008000"),
                                       Color.parseColor("#ADFF2F"))
                        );
                        gradientDrawable.cornerRadius = 0f;
    
                       //Set Gradient
                       linearLayout.setBackground(gradientDrawable);
    

    Result

提交回复
热议问题