简体   繁体   中英

Set ImageView resource from Java

How to set image from android drawables at ImageView? Not from R.drawable but from defaults... IE a star. I know how to do it in xml, now I want to do the same from Java.

如果默认情况下您是指与android捆绑在一起的可绘制对象,则以与普通可绘制对象相同的方式设置它们,例如imageView.setImageResource(android.R.drawable.stat_notify_sync),您只需在android前面加上R

首先,要在Android环境下使用图像,您必须将图像放置在drawable目录中,并且在应用程序中使用它们的唯一方法是使用类R。该示例以编程方式在android上设置图像Java如下:

YourImageView.setImageResource(R.drawable.name_of_your_image);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM