版權聲明:本文為博主原創文章,未經博主允許不得轉載。
前言
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