getResource.getDrawable()以及getResource.getColos()这一类方法已然呗Google废弃,我们现在需要使用新的方法去实现
ContextCompat
1 | ContextCompat.getColor(); |
使用ContextCompat.getDrawable();时相当于
1 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { |
参数为context 和resId 这个方法获取到的资源会受到主题属性的控制
ResourcesCompat
1 | ResourcesCompat.getDrawable(getResources(), R.drawable.name, null); |
参数的最后一个可以人为控制当前的资源是否拥有主题属性