resources - Constant states do not match in developer preview android L -
i trying in if-statement, works in every version of android (16 or higher because of getdrawable) except android l (tested on latest). code following:
if (item.geticon().getconstantstate().equals(getresources().getdrawable(r.drawable.add_to_fav_normal).getconstantstate())
any help/hints or explanation appreciated!
use item.getcontext().getdrawable(int)
or equivalent contextcompat
method.
starting in api 21, framework widgets load drawables utilize context.getdrawable()
applies context's current theme during inflation. calls getresources().getdrawable(..., gettheme())
internally, utilize context.getresources().getdrawable(..., context.gettheme())
.
if (item.geticon().getconstantstate().equals(item.getcontext() .getdrawable(r.drawable.add_to_fav_normal).getconstantstate())
in general, though, shouldn't rely on check. there no api guarantees around constant state you'll receive particular drawable.
android resources imageview equals android-5.0-lollipop
No comments:
Post a Comment