set Background - Android android.app

Android examples for android.app:Activity

Description

set Background

Demo Code

import android.app.Activity;
import android.graphics.drawable.Drawable;
import android.view.View;

public class Main{

    public static void setBackground(Activity activity, int viewID,
            int backgroundID) {
        Drawable background = activity.getResources().getDrawable(
                backgroundID);//from  ww w . java2 s . 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