android - Custom EditText style with appcompat v7 -
i created custom view extending edittext , specified attribute style change background tint color.
public class customedittext extends edittext { public customedittext (context context) { this(context, null); } public customedittext (context context, attributeset attrs) { this(context, attrs, r.attr.customedittextstyle); } public customedittext (context context, attributeset attrs, int defstyle) { super(context, attrs, r.attr.customedittextstyle); } // other code... }
then added attribute style:
<resources> <attr name="customedittextstyle" format="reference" /> <resources>
i using theme.appcompat in app. overriding colorprimary, colorprimarydark , coloraccent.
<style name="apptheme.base" parent="theme.appcompat.light.darkactionbar"> <item name="colorprimary">@color/blue</item> <item name="colorprimarydark">@color/blue_dark</item> <item name="coloraccent">@color/blue_accent</item> <item name="customedittextstyle">@style/customedittext</item> </style> <style name="customedittext" parent="widget.appcompat.edittext"> <item name="colorprimary">@color/blue</item> <item name="colorprimarydark">@color/blue_dark</item> <item name="coloraccent">@color/blue_accent</item> </style>
the edittext background colors working fine, however, can't same custom edittext.
i have tried using code changes overall state, such states uses same color.(https://stackoverflow.com/a/28433337)
edittext.getbackground().setcolorfilter(getresources().getcolor(r.color.your_color), porterduff.mode.src_atop);
is there way apply appcompat style in custom view? appcompat issue or did wrong in customedittext? idea appreciated. thanks!
as of api 21 must subclass appcompatedit text. same true supported widgets. use appcompat* tinting , other supported functionality.
Comments
Post a Comment