【问题标题】:getResources().getDrawable(rippleResourceId, null) return rippleDrawable with the wrong colorgetResources().getDrawable(rippleResourceId, null) 以错误的颜色返回rippleDrawable
【发布时间】:2020-05-28 22:03:10
【问题描述】:

我使用android resourceId android.R.attr.actionBarItemBackground 设置波纹。

在一个项目上它工作正常。在另一个项目上,我更改了 RippleDrawable 半径,但随后波纹颜色变为粉红色。

    int rippleResourceId = // android.R.attr.actionBarItemBackground from current context
    if (VERSION.SDK_INT >= VERSION_CODES.M) {
      RippleDrawable drawable =
          (RippleDrawable) getResources().getDrawable(rippleResourceId, null);
      drawable.setRadius(
          getContext()
              .getResources()
              .getDimensionPixelSize(R.dimen.ripple_radius));
 myFrameLayout.setBackground(drawable);
    } else {
       myFrameLayout.setBackgroundResource(discRippleResourceId);
    }

有这个问题吗?

【问题讨论】:

  • 你在使用材料设计库吗?
  • setBackground 和 setBackgroundResource?
  • @PankajKumar 它有什么变化?因为我明确地解决了drawable,然后设置它而不是id。没有?
  • @EladBenda 不,实际上两者都是一样的。我怀疑,但在研究实施后,我意识到你是对的。

标签: android android-drawable ripple rippledrawable


【解决方案1】:

发送一个空主题会导致这种差异

getDrawable(rippleResourceId, null);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-06-06
    • 2012-07-28
    • 2016-01-16
    • 1970-01-01
    • 2020-11-11
    • 1970-01-01
    • 2023-03-17
    相关资源
    最近更新 更多