Reputation: 49
I would like to set the background of my android application to a tri-color gradient. I have tried the following line of code:
binding.splashScreenRelativeLayout.background = gradient
Where binding is the data binding variable to my XML layout and gradient is
gradient = GradientDrawable(GradientDrawable.Orientation.BL_TR, intArrayOf(startColor, midColor, endColor))
.
I have also tried creating a custom drawable class and using it as an XML element but without any success as I haven't found much documentation using XML with custom drawables
Upvotes: 1
Views: 190
Reputation: 26
Have you tried to create a drawable resource file? You can create an shape and inside of that you can set a gradient with start, center and end color, like this:
<shape
xmlns:android="http://schemas.android.com/apk/res/android">
<gradient
android:startColor="@color/colorPrimary"
android:centerColor="@color/colorAccent"
android:endColor="@color/colorPrimaryDark"/>
</shape>
then you'll have a tricolored gradient. Now all you gonna do is setting this as background of your layout file.
Upvotes: 1