在 Android Studio 上,它一直说 setBackgroundDrawable()
以及 getWidth
和 getHeight
已弃用。
我该如何解决这个问题?
ivImage.setBackgroundDrawable(gd);
Display display = getWindowManager().getDefaultDisplay();
int width = display.getWidth();
int height = display.getHeight();
最佳答案
只需阅读该函数的文档并按照他们告诉您的去做。为了
ImageView.setBackgroundDrawable
,文档告诉你使用setBackground
:
public void setBackgroundDrawable (Drawable background) Added in API level 1
This method was deprecated in API level 16. use setBackground(Drawable) instead
对于 Display
上的 getWidth
和 getHeight
,文档告诉您这样做:
public int getWidth () Added in API level 1
This method was deprecated in API level 13. Use getSize(Point) instead.
这归结为
Point point = null;
getWindowManager().getDefaultDisplay().getSize(point);
int width = point.x;
int height = point.y;
关于android - 如何解决 setBackgroundDrawable 被弃用的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35252706/