-3

I have the following Android ImageButton:

<ImageButton
    android:id="@+id/myButton"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/my_button"
    android:background="@null" />

The button displays a circle image with a transparent plus in the middle. When the user is scrolling I want to change the color of this button based on the offset.

I tried using setBackgroundColor() but this is not the correct way of doing it and it does not work. It must be more the tint color I guess.

How can I change the color of the ImageButton image dynamically?

Michael
  • 32,527
  • 49
  • 210
  • 370

1 Answers1

2

You may want to try an answer by vokilam to a similar question:

ImageButton button = (ImageButton) this.findViewById(R.id.button_i_want_to_modify);
button.setColorFilter(Color.argb(255, 255, 255, 255)); // White Tint

Found here: How do I change the tint of an ImageButton on focus/press

Community
  • 1
  • 1
Yuri Predborski
  • 186
  • 1
  • 1
  • 12