Android 5.0 Lollipop: setColorFilter "leaks" onto other buttons -
i using setcolorfilter
set color filter of 1 of button. has been working until android 5.0 lollipop update. now, color filter seems leak onto other buttons, when close activity , reopen (it resets if close app , reopen).
my styles.xml (v21): (same older except here parent material, before holo)
<style name="theme.fullscreen" parent="@android:style/theme.material.light.noactionbar.fullscreen"> <item name="android:buttonstyle">@style/standardbutton</item> <item name="android:windowtranslucentstatus">true</item> </style>
my styles.xml (for versions):
<style name="standardbutton" parent="android:style/widget.button"> <item name="android:background">@android:drawable/btn_default</item> </style>
my button:
<button android:id="@+id/mainmenubutton" android:layout_width="wrap_content" android:layout_height="wrap_content" android:onclick="mainmenu" android:text="@string/button_mainmenu" android:visibility="gone" />
my code:
button mainmenubutton = (button) findviewbyid(r.id.mainmenubutton); mainmenubutton.getbackground().setcolorfilter(new porterduffcolorfilter(getresources().getcolor(r.color.light_green), porterduff.mode.multiply)); mainmenubutton.setvisibility(view.visible);
the color:
<color name="light_green">#5cd65c</color>
the result:
i open app, game activity , buttons displaying correctly. press button set color filter, go main menu , reopen game activity , buttons green.
any ideas?
the problem background drawable
reused across many views. ensure drawable
not shared between multiple views should use mutate
method.
see: mutate()
example code:
drawable background = mainmenubutton.getbackground(); background.mutate(); background.setcolorfilter(new porterduffcolorfilter(getresources().getcolor(r.color.light_green), porterduff.mode.multiply)); mainmenubutton.setbackground(background);
Comments
Post a Comment