AndroidDev
AndroidDev

Reputation: 123

GradientDrawable change angle programmatically

I have following 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>

Upvotes: 12

Views: 7390

Answers (2)

Kevin Oyowe - Koyowe
Kevin Oyowe - Koyowe

Reputation: 51

Try:

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

Upvotes: 3

Tim Kranen
Tim Kranen

Reputation: 4222

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

Upvotes: 14

Related Questions