Xamarin – Gradient Background for Layout in Android
We have seen how to add an image as background to your layout in previous posts. In this post, we would see how we achieve a Linear Gradient color background for the Layout in Android.
As usual you need to create an XML file for this, add it to the Drawable folder.
The XML file would be under Drawable folder which is under Resources.
Now we would add a shape control of type rectangle and then add gradient to it. A gradient would have startcolor, endcolor and angle as android attributes.
Let’s link this to the LinearLayout’s background attribute.
Let’s run the application and you would see the StartColor is from the left and ends in the Right.
Let’s do change in angle and make it to 90.
Let’s run the application again and you would see the angle changed the direction of the gradient. That is from bottom to top. You get the idea I hope.
Hope this quick post helps you, thanks for reading.
Full Source Code: Click Here