Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing an ImageResource (drawable) programmatically

Tags:

java

android

I am currently using the @android:drawable/presence_online as the srcCompat for a ImageView.

I would like to change it programmatically to @android:drawable/presence_offline.

I tried the code below but it didn't work.

    final ImageView imgPresence = (ImageView) findViewById(R.id.imgPresence);
    imgPresence.setImageResource(R.drawable.presence_offline);

Any ideas?

like image 338
Kaguei Nakueka Avatar asked Mar 22 '26 15:03

Kaguei Nakueka


1 Answers

You missed android in the resource id.

Instead of

imgPresence.setImageResource(R.drawable.presence_offline);

use this:

imgPresence.setImageResource(android.R.drawable.presence_offline);
like image 72
Srijith Avatar answered Mar 25 '26 07:03

Srijith