Java tutorial
//package com.java2s; // Use of this source code is governed by a BSD-style license that can be import android.annotation.SuppressLint; import android.graphics.drawable.Drawable; import android.os.Build; import android.view.View; public class Main { /** * @see android.view.View#setBackground(android.graphics.drawable.Drawable) */ @SuppressLint("NewApi") public static void setBackgroundForView(View view, Drawable drawable) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { view.setBackground(drawable); } else { view.setBackgroundDrawable(drawable); } } }