2015-11-09 38 views
0

getDrawable被取消。我怎樣才能重寫這段代碼。我無法找到答案。如何替換getDrawable

public static List<Product> getCatalog(Resources res){ 
    if(catalog == null) { 
     catalog = new Vector<Product>(); 
     catalog.add(new Product("Dead or Alive",src.getDrawable(R.drawable.deadoralive), 
       "Dead or Alive by Tom Clancy with Grant Blackwood", 29.99)); 
     catalog.add(new Product("Switch", res 
       .getDrawable(R.drawable.switchbook), 
       "Switch by Chip Heath and Dan Heath", 24.99)); 
     catalog.add(new Product("Watchmen", res 
       .getDrawable(R.drawable.watchmen), 
       "Watchmen by Alan Moore and Dave Gibbons", 14.99)); 
    } 

    return catalog; 
} 

什麼是使用它的新功能最好的方法。

+1

它是一種重複的問題 –

+0

我知道有很多問題已經被問及geDrawable在這個網站,但我是新Android開發,所以我需要確切的答案,因爲我無法做到這一點。 – vikky

回答

1

。例如。

Drawable drawable = ContextCompat(context, R.drawable.deadoralive);