【问题标题】:Need Integer resource id of drawable resources dynamically动态需要可绘制资源的整数资源ID
【发布时间】:2015-06-14 19:07:10
【问题描述】:

我需要动态设置通知图像图标,其名称动态传递给我的类。 为此,我需要设置 builder.setSmallIcon(int res_id)。我用谷歌搜索了它,但人们使用了 setDrawableImage() 的例子 我看过这篇文章,并在我的代码中相应地实现了。

   //blah blah lines of code
   String uri = "@drawable/a";
   int imageResource = con.getResources().getIdentifier(uri,null, con.getPackageName());
   Drawable res = con.getResources().getDrawable(imageResource);
   builder.setSmallIcon(res);
   //blah blah code lines

当然,这会显示错误,因为 setSmallIcon() 需要将整数传递给它。 con 是传递给我的构造函数的上下文。 我看过How to set the image from drawable dynamically in android?的帖子

【问题讨论】:

    标签: android dynamic android-resources


    【解决方案1】:

    当然,这会显示错误,因为 setSmallIcon() 需要将整数传递给它。

    您已经有了所需的整数。您将其命名为 imageResource。将imageResource 传递给setSmallIcon()

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-04-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-06-23
      • 2018-02-27
      相关资源
      最近更新 更多