In xml, I often do this to emulate onClick effect:
Based on @Wirling answer we can use foreground to set both the color and the ripple effect
Note: Foreground requires android API level 23(M) and above:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
TypedValue outValue = new TypedValue();
getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground, outValue, true);
view.setForeground(getDrawable(getContext(), outValue.resourceId));
}