set View Gradient Background - Android User Interface

Android examples for User Interface:View Background

Description

set View Gradient Background

Demo Code


//package com.java2s;
import android.graphics.Color;
import android.graphics.drawable.GradientDrawable;
import android.view.View;

public class Main {
    public static void setGradientBackground(View view, int[] colors) {

        int[] color = new int[] { Color.parseColor("#8FC550"), Color.WHITE };

        if (colors != null && colors.length > 2) {
            color = colors;//  w w w.j av  a  2 s .co m
        }

        GradientDrawable gd = new GradientDrawable(
                GradientDrawable.Orientation.BOTTOM_TOP, color);
        gd.setCornerRadius(0f);
        view.setBackgroundDrawable(gd);
    }
}

Related Tutorials