0

Got the following code in the activity:

LinearLayout view = (LinearLayout) this.findViewById(R.id.viewid);
Drawable drawable = getResources().getDrawable(R.drawable.drawableid);

if (Build.VERSION.SDK_INT >= 16)
    view.setBackground(drawable);
else
    view.setBackgroundDrawable(drawable);

Eclipse gives me an error on setBackground: "Call requires API level 16 (current min is 8): android.widget.LinearLayout#setBackground", and a warning on setBackgroundDrawable: "The method setBackgroundDrawable(Drawable) from the type View is deprecated". I cannot compile my project with this error.

Why ADT doesn't detect that both setBackground* methods are valid with the version check?

alterionisto
  • 77
  • 1
  • 8

1 Answers1

0

I cannot compile my project with this error.

Sure you can. Use the quick-fix to add @TargetApi(Build.VERSION_CODES.JELLY_BEAN) to the method in which this code appears.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491