So my sdk goes from 15 to 21 and when I call setBackgroundDrawable()
, Android Studio tells me that it's deprecated.
I thought of going around it using:
int sdk = android.os.Build.VERSION.SDK_INT;
if(sdk < android.os.Build.VERSION_CODES.JELLY_BEAN) {
layout.setBackgroundDrawable(getResources().getDrawable(R.drawable.img_wstat_tstorm));
} else {
layout.setBackground(getResources().getDrawable(R.drawable.img_wstat_tstorm));
}
But then, I get an error at "setBackground()".
So, how would you deal with it?
It's an interesting topic. The way you are doing it is correct, apparently. It is actually just a naming decision change. As this answer points out,
setBackground()
just callssetBackgroundDrawable()
:You can see this thread for more information about all of this.