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 calls setBackgroundDrawable()
:
public void setBackground(Drawable background) { //noinspection deprecation setBackgroundDrawable(background); } @Deprecated public void setBackgroundDrawable(Drawable background) { ... }
You can see this thread for more information about all of this.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With