Gradient Program Angle

I have xml for GradientDrawable. How can I change the angle programmatically?

<shape xmlns:android="http://schemas.android.com/apk/res/android"> <gradient android:type="linear" android:angle="45" android:startColor="#FF0000" android:endColor="#00FF00" /> </shape> 
+5
source share
2 answers

GradientDrawable has a method called: .setOrientation(GradientDrawable.Orientation orientation) , you can change the gradient orientation with this. You need to inflate XML as a GradientDrawable.

+6
source

Try:

 GradientDrawable appTheme = new GradientDrawable(GradientDrawable.Orientation.BL_TR, colors); 
+1
source

All Articles