How to set ImageButton property of app:srcCompat="@drawable/pic" programmatically?

Isaac Darlong picture Isaac Darlong · Jul 5, 2016 · Viewed 39.9k times · Source

How to set the ImageButton property of

app:srcCompat="@drawable/pic"

programmatically?

Something like myImageButton.setBackgroundResource(R.drawable.eng2); but the property of app:srcCompat.

Answer

Prerak Sola picture Prerak Sola · Jul 5, 2016

You need to use setImageResource() method.

imageButton.setImageResource(R.drawable.eng2);