问题描述
我刚刚升级我的Android项目的建设目标为17 API,而我现在获取有关pcated setBackgroundDrawable感德$ P $警告。答案似乎是使用的setBackground,但是这不是在旧版本可用。
有任何实际的优势,使用新的方法,还是谷歌只是想改名字?我没有看到任何一点与平台版本检查或反射,如果两项工作是一样的。
复杂我code他们似乎只想要改名字,看<一href="http://grep$c$c.com/file/repository.grep$c$c.com/java/ext/com.google.android/android/4.1.1_r1/android/view/View.java#View.setBackground%28android.graphics.drawable.Drawable%29"相对=nofollow>来源$ C $ C :
公共无效的setBackground(可绘制背景){
// noinspection德precation
setBackgroundDrawable(背景);
}
pcated @德$ P $
公共无效setBackgroundDrawable(可绘制背景){...}
所有的工作都在 setBackgroundDrawable仍在进行()
。现在,你可以忽略去precation警告,但明白,在未来的API setBackgroundDrawable()
将被移除。
如果你很好奇,<一个href="http://grep$c$c.com/file/repository.grep$c$c.com/java/ext/com.google.android/android/4.1.1_r1/android/view/View.java#View.setBackgroundResource%28int%29"相对=nofollow> setBackgroundResource(INT渣油)
简单的创建从资源ID和呼叫的setBackground()被拉伸
(而这又要求 setBackgroundDrawable()
)
I just upgraded my Android project's build target to API 17, and I'm now getting warnings about setBackgroundDrawable being deprecated. The answer appears to be to use setBackground, but that's not available in older versions.
Is there any actual advantage to using the new method, or did Google just want to change the name? I don't see any point in complicating my code with platform version checks or reflection if the two work the same.
They seemed to only want to change the name, look at the source code:
public void setBackground(Drawable background) {
//noinspection deprecation
setBackgroundDrawable(background);
}
@Deprecated
public void setBackgroundDrawable(Drawable background) { ... }
All of the work is still done in setBackgroundDrawable()
. For now, you can ignore the deprecation warnings but understand that in some future API setBackgroundDrawable()
will be removed.
In case you are curious, setBackgroundResource(int resid)
simply creates a drawable from the resource ID and calls setBackground()
(which again calls setBackgroundDrawable()
)...
这篇关于setBackgroundDrawable()和的setBackground之间差()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!