skip to Main Content

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 ?*** );

2

Answers


  1. Chosen as BEST ANSWER

    xml

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

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


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

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

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search