在Android Studio上,它一直在说setBackgroundDrawable()以及getWidth和getHeight都被弃用了。
我该如何解决这个问题?
ivImage.setBackgroundDrawable(gd);
Display display = getWindowManager().getDefaultDisplay();
int width = display.getWidth();
int height = display.getHeight();发布于 2016-02-07 19:20:10
只需阅读该函数的文档,然后按照它们告诉您的做。对于ImageView.setBackgroundDrawable,文档告诉您使用setBackground
1级接口增加
公共空setBackgroundDrawable (可绘制背景)
此方法在API级别16中已弃用。请改用setBackground(可绘制的)。
对于Display上的getWidth和getHeight,文档告诉您这样做:
在
级别1中添加了公共int getWidth ()
此方法在API级别13中已弃用。请改用getSize(Point)。
这可以归结为
Point point = null;
getWindowManager().getDefaultDisplay().getSize(point);
int width = point.x;
int height = point.y;发布于 2016-02-07 19:18:05
只需用.setBackground(gd);替换.setBackgroundDrawable(gd);即可
这很可能会解决你的问题
ivImage.setBackground(gd);
Display display = getWindowManager().getDefaultDisplay();
int width = display.getWidth();
int height = display.getHeight();发布于 2016-11-09 18:32:19
如果你有一个资源id,那么我们可以使用setBackgroundResource(),它是API level 1。
int sdk = android.os.Build.VERSION.SDK_INT;
if(sdk < android.os.Build.VERSION_CODES.JELLY_BEAN) {
setBackgroundDrawable();
} else {
setBackground();
}根据source,setBackground()只调用setBackgroundDrawable()
public void setBackground(Drawable background) {
setBackgroundDrawable(background);
}
@Deprecated
public void setBackgroundDrawable(Drawable background) { ... }https://stackoverflow.com/questions/35252706
复制相似问题