Skip to content Skip to sidebar Skip to footer

How To Make A Gradient Background For A Linearlayout?

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

Solution 1:

<?xml version="1.0" encoding="utf-8"?><shapexmlns:android="http://schemas.android.com/apk/res/android"android:shape="rectangle"><gradientandroid:startColor="#006499"android:endColor="#0093d7"android:angle="90" /></shape>

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

Solution 2:

Besides xml you can also use GradientDrawable it has corresponding methods for all xml attributes

Post a Comment for "How To Make A Gradient Background For A Linearlayout?"