Issue
I have this:
round_button.xml
<xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true">
<shape android:shape="oval">
<solid android:color="#dec60000"/>
<size android:width="150dp" android:height="150dp"/>
</shape>
</item>
<item android:state_pressed="false">
<shape android:shape="oval">
<solid android:color="#860000"/>
<size android:width="150dp" android:height="150dp"/>
</shape>
</item>
My Button:
<Button
android:id="@+id/incrementBTN"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:background="@drawable/round_button"
android:onClick="onClick"
android:soundEffectsEnabled="true"
android:text="0"
android:textSize="50sp"
tools:ignore="HardcodedText" />
Dynamically, I want to change the background color (which is defined in the round_button xml) programmatically. Is there a way I can do this?
Solution
I solved it by setting a ColorFilter:
Drawable mDrawable = context.getResources().getDrawable(R.drawable.balloons);
mDrawable.setColorFilter(new PorterDuffColorFilter(0xffff00,PorterDuff.Mode.MULTIPLY));
myButton.setResource(mDrawable);
Answered By - Ali Bdeir
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.