问题描述
所以,我的SDK变为15至21,当我打电话 setBackgroundDrawable()
,Android的工作室告诉我,这是pcated德$ P $。
So my sdk goes from 15 to 21 and when I call setBackgroundDrawable()
, Android Studio tells me that it's deprecated.
我想用它周围的打算:
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));
}
不过,我得到一个错误的的setBackground()。
But then, I get an error at "setBackground()".
那么,你会如何处理呢?
So, how would you deal with it?
推荐答案
这是一个有趣的话题。你正在做的方式是正确的,显然。它实际上只是一个命名决策的变化。由于这个答案指出,的setBackground()
只是调用 setBackgroundDrawable()
:
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.
这篇关于setBackgroundDrawable()去precated的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!