androidandroid-drawableripplerippledrawable

getResources().getDrawable(rippleResourceId, null) return rippleDrawable with the wrong color


I use android resourceId android.R.attr.actionBarItemBackground to set ripple.

On one item it works fine. On anther item I change the RippleDrawable radius, but then the ripple color changes to pink.

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

Anyhow had this problem?


Solution

  • sending a null theme caused this difference

    getDrawable(rippleResourceId, null);