xml layout - Android pass parent view's 'pressed' state to child views -
there many question here on asking way prevent child view copying parents pressed or selected states. however, i'm asking other way around here :) - i've seen weird behavior in 1 of apps:
when running app on 4.0.4 device (api 15) behavior saw matched apparent default, is: parent forwards state down of child views.
when running same app without changes on higher api level (android 4.4) behavior changes: parent not forward state.
i introduced duplicateparentstate
in xml layout relevant child views, not seem here.
is known 'issue' or planned change in behavior api 15 api >> 15?
how can make sure states forwarded across api levels?
if of / relevance here: subview want duplicate parents state custom imageview
adds tintcolors - since behavior correct on 4.0.4 there should not mistakes in class?
public class incimageview extends imageview { private int _tintcolor; private int _highlightedtintcolor; private int _selectedtintcolor; public incimageview(context context, attributeset attrs) { super(context, attrs); this.setfocusable(true); this.setclickable(true); typedarray array = context.obtainstyledattributes(attrs, r.styleable.incimageview); _tintcolor = array.getint(r.styleable.incimageview_tintcolor, getresources().getcolor(r.color.inc_tint)); this.setcolorfilter(_tintcolor); _selectedtintcolor = array.getint(r.styleable.incimageview_selectedtintcolor, _tintcolor); _highlightedtintcolor = array.getint(r.styleable.incimageview_highlightedtintcolor, _tintcolor); array.recycle(); } @override public void setselected(boolean selected) { super.setselected(selected); this.setcolorfilter((selected ? _selectedtintcolor : _tintcolor)); } @override public void setpressed(boolean pressed) { super.setpressed(pressed); this.setcolorfilter((pressed ? _highlightedtintcolor : (this.isselected() ? _selectedtintcolor : _tintcolor))); } }
i found solution:
if have @ imageview
subclass above, in constructor clickable
& focusable
set true
.
turns out mistake. parent won't forward state when child clickable. - still not explain why above code works on 4.0.4 breaks on 4.4
anyway, leaving clickable & focusable = false
solves problem.
Comments
Post a Comment