【问题标题】:How replace getDrawable [duplicate]如何替换getDrawable [重复]
【发布时间】:2016-02-09 22:15:55
【问题描述】:

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;
}

什么是使用它功能的新的最佳方式。

【问题讨论】:

  • 这是一个重复的问题
  • 我知道在这个网站上有人问了很多关于 geDrawable 的问题但是我是 Android 开发的新手,所以我需要确切的答案,因为我无法这样做。

标签: android android-widget android-drawable


【解决方案1】:

使用ContextCompat.getDrawable。例如

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

【讨论】:

    【解决方案2】:

    从这个thread,你必须使用

    ContextCompat.getDrawable(context, R.drawable.***)
    

    【讨论】:

      猜你喜欢
      • 2019-02-20
      • 1970-01-01
      • 1970-01-01
      • 2016-03-21
      • 1970-01-01
      • 2018-02-24
      • 2011-10-21
      • 2020-11-12
      • 1970-01-01
      相关资源
      最近更新 更多