You should get Drawable from the button, since the setColorFilter that you are trying to use (in your setup) is applicable to them.
ImageButton btn = (ImageButton) myLayout.findViewByID(R.id.my_button); int mycolor = getResources().getColor(R.color.best_color); btn.getDrawable().setColorFilter(mycolor, PorterDuff.Mode.SRC_ATOP);
If you have the correct reference to the Drawable,
eg textView.getCompoundDrawables()[2].setColorFilter(...);
which in its xml:
<TextView ... android:drawableLeft="..." ... />
you can use myDrawableObject.setColorFilter () as you like.
Edit:
For ImageButton for imageButton.getDrawable() for imageButton.getDrawable() corresponds to android:src="..." , and imageButton.getBackground() corresponds to the property android:background="..." . Make sure you type setColorFilter in the correct path.
source share