What you already posted is very true:
- Unable to create ripple selector by specifying only color
- cannot use theme attributes in xml using API <21
I donβt think there is anything more than just using a library or coding. From the code, you can generate ripples, use theme attributes, and more.
I had the same problem and I just wrote a bunch of classes to easily create ripples. For example, to get the colors of themes, I wrote a simple ColorStateList class:
public class ControlCheckedColorStateList extends ColorStateList {
public ControlCheckedColorStateList(Context context) {
super(new int[][]{
new int[]{android.R.attr.state_checked},
new int[]{}
}, new int[]{
getThemeColor(context, R.attr.colorPrimary),
getThemeColor(context, R.attr.colorControl)
});
}
public static int getThemeColor(Context context, int attr) {
Resources.Theme theme = context.getTheme();
TypedValue typedvalueattr = new TypedValue();
theme.resolveAttribute(attr, typedvalueattr, true);
return typedvalueattr.resourceId != 0 ? context.getResources().getColor(typedvalueattr.resourceId) : typedvalueattr.data;
}
}
Then I added attributes for color and ripple style. I also had to override the setBackground methods, so setting ripples to represent does not clear my background. Now setting a ripple with a custom color is as simple as:
<carbon.widget.Button
android:background="#ffffffff"
app:carbon_rippleColor="#40ff0000"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
, . , , , . github. - , .