// 新
ContextCompat.getColor(mContext, R.color.sample)
// 旧
mContext.getResources().getColor(R.color.sample)
// ContextCompat
public static final int getColor(Context context, int id) {
final int version = Build.VERSION.SDK_INT;
if (version >= 23) {
return ContextCompatApi23.getColor(context, id);
} else {
return context.getResources().getColor(id);
}
}
Last active
June 25, 2019 07:27
-
-
Save ochim/2459f2fcd2962ef42a10ebdec5404def to your computer and use it in GitHub Desktop.
Android 6.0 Marshmallow (android sdk 23)からは getColorではなくContextCompat.getColor を使いましょう
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment