본문 바로가기

나의 플랫폼/안드로이드

[Android] getDrawable, getColor deprecated

336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

Resource로 Drawable이나 Color를 얻어오면 어떤 함수를 써야 할지 고민이 됩니다.

그냥 아래 소스를 API로 만들어 놓은 후 호출하면 간편 합니다.


public int getColor(Context context, int id) {
final int version = Build.VERSION.SDK_INT;
if (version >= Build.VERSION_CODES.M) {
return context.getColor(id);
} else {
return context.getResources().getColor(id);
}
}

public Drawable getDrawable(Context context, int id) {
final int version = Build.VERSION.SDK_INT;
if (version >= Build.VERSION_CODES.LOLLIPOP) {
return context.getDrawable(id);
} else {
return context.getResources().getDrawable(id);
}
}


참고하세요~