Setting a drawable as a background from a String in Android Studio

18 Views Asked by At

I have an image with the name "simba.jpg" which I want to set as the background of a LinearLayout component. How can I do so?

A naive (and wrong) attempt at what I'm trying to do would be like so:

LinearLayout image = findViewById(R.id.image);
image.setBackground("simba.jpg");

The code I've tried from other posts (e.g. this or this) do not work, either because they apply to an ImageView or because the methods used are deprecated.

0

There are 0 best solutions below