Reputation: 53
I want to change the picture of the background in my app in Android Studio depending on a few conditions. This is my code:
switch (sky_state) {
case "SUNNY":
// Here I want to change the background
break;
}
I know how to change it in the XML file of the layout, but is it possible to access this property from the code outside the layout file?
Upvotes: 2
Views: 1754
Reputation: 1670
Yes, you can do that... Use the following line of code for that particular view...
switch (sky_state) {
case "SUNNY":
view.setBackground(getResources().getDrawable(R.drawable.ic_send));
break;
}
Let me know if this works for you and mark as an answer if it does, so that it would be useful to others.....
Upvotes: 1