码迷,mamicode.com
首页 > 移动开发 > 详细

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

时间:2017-05-14 10:56:37      阅读:215      评论:0      收藏:0      [点我收藏+]

标签:through   targe   原创   span   知识库   lan   csdn   http   例子   

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

前言

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过时的替代方法

标签:through   targe   原创   span   知识库   lan   csdn   http   例子   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!