Java tutorial
//package com.java2s; //License from project: Open Source License import android.annotation.TargetApi; import android.graphics.drawable.Drawable; import android.os.Build; import android.os.Build.VERSION; import android.os.Build.VERSION_CODES; import android.view.View; public class Main { @SuppressWarnings("deprecation") @TargetApi(Build.VERSION_CODES.JELLY_BEAN) public static void setBackground(View view, Drawable background) { if (isApiLevel(VERSION_CODES.JELLY_BEAN)) view.setBackground(background); else view.setBackgroundDrawable(background); } /** * Returns true if the device supports the specified API level (or greater). */ public static boolean isApiLevel(int apiLevel) { return (VERSION.SDK_INT >= apiLevel); } }