Importing resources without Deprecated error

suggest change

On Android API 23 and higher, you will often see this situation:

This situation is caused by the structural change of the Android API regarding getting the resources. Now the function:

public int getColor(@ColorRes int id, @Nullable Theme theme) throws NotFoundException

should be used. The support-v4 library has another solution.

Add the following dependency to the app build.gradle file:

compile 'com.android.support:support-v4:24.0.0'

Then all methods from support library are available:

ContextCompat.getColor(context, R.color.colorPrimaryDark);
ContextCompat.getDrawable(context, R.drawable.btn_check);
ContextCompat.getColorStateList(context, R.color.colorPrimary);
DrawableCompat.setTint(drawable, ContextCompat.getColor(context, R.color.colorPrimary));
ContextCompat.getColor(context, R.color.colorPrimaryDark);

More methods from the support library can be used:

ViewCompat.setElevation(textView, 1F);
ViewCompat.animate(textView);
TextViewCompat.setTextAppearance(textView, R.style.AppThemeTextStyle);
...

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents