How to make a gradient background for a LinearLayout?

前端 未结 2 954
我寻月下人不归
我寻月下人不归 2021-02-09 16:19

I was wondering, what would be the best way to make a gradient background for a LinearLayout in java ( not xml ) ?

Any ideas?

Thanks!

2条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-02-09 16:42

    
    
        
    
    

    Set here startColor and endColor as your requirement and save this file in drawable folder

    and in LinearLayout you can set this as setBackground="@drawable/your gradient filename"

    Using java code you can do same thing using GradientDrawable

提交回复
热议问题