2017-02-27 83 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)); 
相關問題