Home > Software engineering >  set image resource from android native resources, programmatically
set image resource from android native resources, programmatically

Time:07-02

a little question.

IMAGE adding in the drawable folder, this code work.

XML

android:src="@drawable/myImage"

JAVA

image1.setImageResource(R.drawable.myOtherImage);

But,

IMAGE get with android studio when i use drag and drop palette editor :

XML

 app:srcCompat="@android:drawable/presence_offline"

JAVA

image2.setImageResource( ***what code here  for use presence_online ?*** );

Merci =).

CodePudding user response:

xml

image2.setImageResource(android.R.drawable.presence_online);

R if you use android 11.0(R) sdk 30.

Sorry I don't know how to "googleIsMyFriend".

CodePudding user response:

for handle Android API above 16 and above 21 use this code.

imageView.setImageDrawable(ContextCompat.getDrawable(context, R.drawable.ic_profile))

  • Related