Have a question! getDrawable() is deprecated in API 22. So, if I make an app with the min API 16, how can I set an image?
I saw that I can use getDrawable(int id, theme) , but this was added in API 21, so I can't use it.
I've tried setImageDrawable(ResourcesCompat.getDrawable(getResources(), R.drawable.drawableName, null))
but this doesn't work either. Also with ContextCompat or getApplicationContext() it doesn't work.
private ImageView weatherIcon;
weatherIcon=(ImageView)findViewById(R.id.weatherIcon);
if(weatherReportList.size()>0){
DailyWeatherReport report=weatherReportList.get(0);
switch (report.getWeather()){
case DailyWeatherReport.WEATHER_TYPE_CLOUDS:
weatherIcon.setImageDrawable(ResourcesCompat.getDrawable(getResources(), R.drawable.cloudy, null));
weatherIconMini.setImageDrawable(ResourcesCompat.getDrawable(getResources(), R.drawable.cloudy, null));
case DailyWeatherReport.WEATHER_TYPE_RAIN:
weatherIcon.setImageDrawable(ContextCompat.getDrawable(this,R.drawable.rainy));
weatherIconMini.setImageDrawable(ResourcesCompat.getDrawable(getResources(), R.drawable.rainy, null));
default:
weatherIcon.setImageDrawable(ResourcesCompat.getDrawable(getResources(), R.drawable.sunny, null));
weatherIconMini.setImageDrawable(ResourcesCompat.getDrawable(getResources(), R.drawable.sunny, null));
}
This is not a duplicate of that post. I've tried all the methods from there but none on them worked.