前言
Android SDK 升級到 23 之后,getDrawable和getColor方法提示過時。
解決方案
getResources().getColor 替換成 ContextCompat.getColor getResources().getDrawable 替換成 ContextCompat.getDrawable
例子如下:
int color = getResources().getColor(R.color.colorAccent);
替換為
int color2 = ContextCompat.getColor(this, R.color.colorAccent);
Drawable drawable = getResources().getDrawable(R.mipmap.ic_launcher);
替換為
Drawable drawable2 = ContextCompat.getDrawable(this,R.mipmap.ic_launcher);