设置图像资源从android本地资源,编程



IMAGE添加到可绘制文件夹中,此代码有效。

XML

android:src="@drawable/myImage"

JAVA

image1.setImageResource(R.drawable.myOtherImage);

,

当我使用拖放调色板编辑器时,得到android studio的图像:

XML

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

JAVA

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

处理Android API大于16和大于21使用此代码。

imageView.setImageDrawable (ContextCompat。R.drawable.ic_profile getDrawable(上下文))

xml> 如果你使用android 11.0(R) sdk 30.

最新更新