-1

I want to change the background of my framelayout (which holds all my pages!) by:

FrameLayout fl = (FrameLayout)findViewById(R.id.container);
    fl.setBackground(getResources().getDrawable(R.drawable.juraquiz_app_background));

but apparently I cant. Is there a way to do it, so its compatible with APIs lower than 16?

user3432220
  • 101
  • 6

2 Answers2

1

for API's lower that 16 you can use setBackgroundDrawable

tyczj
  • 71,600
  • 54
  • 194
  • 296
1

Use different methods for different APIs:

final Drawable drw = getResources().getDrawable(R.drawable.juraquiz_app_background);
if(android.os.Build.VERSION.SDK_INT < 16)
{
    fl.setBackgroundDrawable(drw);
}
else
{
    fl.setBackground(drw);
}

You will need to add an annotation to your method (or to your class, if you prefer) to get rid of Lint warnings:
@SuppressLint("NewApi")

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115