Android UI How to - Set View Background








Question

We would like to know how to set View Background.

Answer

/* w  ww .  j a v a2 s  .c o  m*/
import android.graphics.drawable.Drawable;
import android.view.View;

class ActivityAttrUtils {
  public static void setBackground(View view, Drawable drawable) {
    // In case of Newer Version
    if (android.os.Build.VERSION.SDK_INT >= 16) {
      view.setBackground(drawable);
    } else {
      view.setBackgroundDrawable(drawable);
    }
  }
}