代码中引用res里的颜色、图片

1、imageButton userImgButton 在代码中设置图片,使用res/Drawable 里的图片

[java] view plaincopy
 
  1. Resources res = getResources();   
  2. Bitmap inDrawable= BitmapFactory.decodeResource(res, R.drawable.user_img_grey);  
  3. userImgButton.setImageBitmap(inDrawable );  

2、imageView  user_pic 在代码中设置背景颜色,使用valus/colors里的颜色:

[java] view plaincopy
 
    1. int resColor = getResources().getColor(R.color.beige);  
    2. user_pic.setBackgroundColor(resColor);  
原文地址:https://www.cnblogs.com/lucky-star-star/p/3693326.html