2017-02-27 139 views
0

我在mipmap目录中有.png图像。知道我想以编程方式将此图像设置为linearLayout后台。并在一些进程删除它之后。以编程方式将mipmap图像设置为linearLayout背景

target SDK : 23 
min SDK : 14 

我应该使用哪个函数?

这可以改变背景颜色:

ll.setBackgroundColor(getResources().getColor(R.color.color_mtn)); 

但如果是背景图片?

+0

l1.setBackgroundResource(getResources()getDrawable(R.mipmap.your_image)。); –

回答

5
ll.setBackgroundResource(R.mipmap.my_image); 

ll.setBackground(ResourcesCompat.getDrawable(getResources(), R.mipmap.my_image, null)) 
0

两者都工作

iv_pic_image.setImageResource(R.mipmap.generic_product_4); 

or 

iv_pic_image.setImageDrawable(getResources().getDrawable(R.mipmap.generic_product_4)); 
相关问题