首页 > 移动平台 > 详细

Android中getDrawable和getColor过时的替代方法

时间:2017-05-14 09:53:05      阅读:403      评论:0      收藏:0      [点我收藏+]

版权声明:本文为博主原创文章,未经博主允许不得转载。

前言

Android SDK 升级到 23 之后,getDrawable和getColor方法提示过时。

解决方案

getResources().getColor 替换成 ContextCompat.getColor
getResources().getDrawable 替换成 ContextCompat.getDrawable

例子如下:
int colorInt = getResources().getColor(R.color.colorAccent);//返回的是color的int类型值:-49023
int colorInt2 = ContextCompat.getColor(this, R.color.colorAccent);//返回的是color的int类型值:-49023

Drawable drawable = getResources().getDrawable(R.mipmap.ic_launcher);
Drawable drawable2 = ContextCompat.getDrawable(this,R.mipmap.ic_launcher);

参考资料

getDrawable,getColor 过时的替代方法

http://blog.csdn.net/u011368551/article/details/50886884 

 

Android中getDrawable和getColor过时的替代方法

原文:http://www.cnblogs.com/whycxb/p/6851583.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!