Search code examples
androidbackground-image

Set mipmap image as linearLayout background programmatically


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?


Solution

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

    or

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