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

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 

 

相关文章:

  • 2021-07-31
  • 2021-11-01
  • 2022-12-23
  • 2022-01-01
  • 2022-01-15
  • 2022-01-02
  • 2021-11-13
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-08-09
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-30
相关资源
相似解决方案