out of box can white ripple/touch state from: ?attr/selectableitembackground have ability color , ripple , touch state works based off color set. nice if via android:theme
i need work api 15+
i know can selector , ripple have selector per color since can not attr in xml pre api 21.
if set color background ripple , touch state doesnt work.
i simple , reusable possible.
is there missing or solution relatively clean.
what you've posted true:
- it's not possible create ripple selector specifying color
- it's not possible use theme attributes in xml using api < 21
i don't think there more using library or coding yourself. code can generate ripples, use theme attributes , more.
i had same problem , wrote bunch of classes easy ripple creation. example theme colors wrote simple class of colorstatelist:
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've added attributes ripple color , style. had override setbackground methods setting ripple view doesn't clear background. setting ripple custom color simple as:
<carbon.widget.button android:background="#ffffffff" app:carbon_ripplecolor="#40ff0000" android:layout_width="wrap_content" android:layout_height="wrap_content" />
lots , lots of lines of code, don't think it's reasonable post of here. if wish, can open widget class library , check if it's you're looking for. can find code on github. in case of questions feel free ask.
Comments
Post a Comment