1、imageButton userImgButton 在代码中设置图片,使用res/Drawable 里的图片
Resources res = getResources();
Bitmap inDrawable= BitmapFactory.decodeResource(res, R.drawable.user_img_grey);
userImgButton.setImageBitmap(inDrawable );
2、imageView user_pic 在代码中设置背景颜色,使用valus/colors里的颜色:
int resColor = getResources().getColor(R.color.beige);
user_pic.setBackgroundColor(resColor);
本文介绍如何在Android应用中为ImageButton和ImageView设置资源文件中的图片及背景颜色,包括使用BitmapFactory从资源文件加载图片并设置给ImageButton,以及从颜色资源文件加载颜色值并设置给ImageView作为背景。
2071

被折叠的 条评论
为什么被折叠?



