Set mipmap image as linearLayout background programmatically

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

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

  

Set mipmap image as linearLayout background programmatically
Asked 4 years, 4 months ago
Active 3 years, 8 months ago
Viewed 2k times


0


I have a .png image in mipmap directory. know I want to set this image as the linearLayout background programmatically. and after some processes remove it.

target SDK : 23
min SDK    : 14
which function shall I use?

this can change background color:

ll.setBackgroundColor(getResources().getColor(R.color.color_mtn));
but where is background image?

android
background-image
Share
Improve this question
Follow
edited Feb 27 '17 at 11:22
asked Feb 27 '17 at 11:13

Shima Erfan
30511 gold badge55 silver badges1717 bronze badges
l1.setBackgroundResource(getResources().getDrawable(R.mipmap.your_image)); – pankaj khedekar Feb 27 '17 at 11:20
Add a comment
2 Answers

6

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

ll.setBackground(ResourcesCompat.getDrawable(getResources(), R.mipmap.my_image, null))
Share
Improve this answer
Follow
answered Feb 27 '17 at 11:17

lelloman
12.8k55 gold badges5656 silver badges7777 bronze badges
Add a comment

0

Both are Working

iv_pic_image.setImageResource(R.mipmap.generic_product_4);

or

iv_pic_image.setImageDrawable(getResources().getDrawable(R.mipmap.generic_product_4));
Share
Improve this answer
Follow
answered Oct 30 '17 at 6:20

Keshav Gera
8,42611 gold badge5757 silver badges4444 bronze badges
Add a comment
Your Answer

https://stackoverflow.com/questions/42484360/set-mipmap-image-as-linearlayout-background-programmatically

  

  

原文地址:https://www.cnblogs.com/pengmn/p/14958086.html