[英]Access Spring Boot Actuator build.version property with @Value
[英]setBackground and getBackground method for Build.version < 16
我对getBackground()和setBackground()方法有疑问 。 我已经设计了一个应用程序,但是现在我发现我没有检查哪个版本是用户android系统(我是android的初学者-很好的一课)。
我的应用程序正在Build.version> 15上工作,因为此版本中引入了上述方法。
我想使用版本16之前存在的类似方法。有什么想法吗?
从API级别1开始, getBackground()
方法就存在了,因此这不应该成为问题。 从API级别16开始仅引入了setBackground(Drawable background)
,因此可能在较旧的平台上引起问题。
您的替代方法是:
setBackgroundColor(int color)
setBackgroundDrawable(Drawable background)
setBackgroundResource(int resid)
在这些方法中,第二个方法自API级别16开始就已弃用,因为它已被您当前使用的setBackground(Drawable background)
取代。 但是,如果您查看该方法的实际实现,则会看到以下内容:
public void setBackground(Drawable background) {
//noinspection deprecation
setBackgroundDrawable(background);
}
因此,此时它所做的全部工作就是将调用委派给已弃用的setBackgroundDrawable()
方法。 因此,如果您想快速修复,只需更改您的代码以使用该代码即可。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.