I want to set the foreground of my CardView to ?attr/selectableItemBackground
.
It work's when I declare the foreground in xml:
android:foreground="?attr/selectableItemBackground"
But I want to set the foreground programmatically. This doesn't work:
int[] attrs = new int[]{R.attr.color_a, R.attr.selectableItemBackground};
TypedArray ta = context.obtainStyledAttributes(attrs);
mColorA = ta.getColor(0, 0);
mSelectableItemBackground = ContextCompat.getDrawable(context, ta.getResourceId(1, 0));
ta.recycle();
...
cardView.setOnClickListener(onClickListener);
cardView.setClickable(true);
cardView.setForeground(mSelectableItemBackground);
However, retrieving the attributes works (mSelectableItemBackground contains a RippleDrawable
), but the foreground doesn't change when I press on the Card.