I have Button and set background resource to it:
button1.setBackgroundResource(R.layout.color00);
color00:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_pressed="true"
android:drawable="@drawable/img00" />
<item
android:state_pressed="false"
android:drawable="@drawable/img00" />
</selector>
then I set alpha to this button
button1.getBackground().setAlpha(50);
and then I have problem. If I set this background resource to button2:
button2.setBackgroundResource(R.layout.color00);
So button1’s alpha set to button2’s alpha with this resource. How to fix it?
Use mutate:
http://developer.android.com/resources/articles/drawable-mutations.html
Drawables use the same state to all their references. User Mutate() for different states.