With new android API 22 getResources().getDrawable()
is now deprecated.
Now the best approach is to use only getDrawable()
.
What changed? <
getDrawable(int drawable) is deprecated in API level 22. For reference see this link.
Now to resolve this problem we have to pass a new constructer along with id like as :-
getDrawable(int id, Resources.Theme theme)
For Solutions Do like this:-
In Java:-
ContextCompat.getDrawable(getActivity(), R.drawable.name);
or
imgProfile.setImageDrawable(getResources().getDrawable(R.drawable.img_prof, getApplicationContext().getTheme()));
In Kotlin :-
rel_week.background=ContextCompat.getDrawable(this.requireContext(), R.color.colorWhite)
or
rel_day.background=resources.getDrawable(R.drawable.ic_home, context?.theme)
Hope this will help you.Thanks.