Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

setBackgroundDrawable() deprecated

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?

like image 796
Makoto Avatar asked Nov 26 '14 04:11

Makoto


1 Answers

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.

like image 189
Alex K Avatar answered Sep 21 '22 22:09

Alex K