set Activity Background - Android Activity

Android examples for Activity:Activity Background

Description

set Activity Background

Demo Code


//package com.java2s;
import android.annotation.SuppressLint;
import android.app.Activity;

import android.graphics.drawable.Drawable;

import android.view.View;

public class Main {
    @SuppressLint("NewApi")
    @SuppressWarnings("deprecation")
    public static void setBackground(Activity activity, int viewID,
            int backgroundID) {
        Drawable background = activity.getResources().getDrawable(
                backgroundID);/*from  www . j a va 2s  .  co m*/
        View view = (View) activity.findViewById(viewID);
        int sdk = android.os.Build.VERSION.SDK_INT;
        if (sdk < android.os.Build.VERSION_CODES.JELLY_BEAN) {
            view.setBackgroundDrawable(background);
        } else {
            view.setBackground(background);
        }
    }
}

Related Tutorials