Skip to content Skip to sidebar Skip to footer

Change Background Image On User's Choice

Guys I want the user to change the background image of all the activities in my app on user selection. I am able to change the background image of the Activity from where am changi

Solution 1:

you cannot access the UI components which are not yet instantiated. Use Intents to pass information across activities (user's choice, or some custom flags or Strings) and use this "extra" information in the launched activity to change the background accordingly.

Read more about intents in the documentation for better understanding and examples.

Solution 2:

You cannot do this.. When you refer a layout file using findViewById(), the android system looks for this in your current ContentView only. (i.e the view which you have set using setContentView() for the current activity). So obvioulsy the sytem will not be able find the resource you are specifying and hence you will get the NullPointerExeption only.

You have to maintain the reference to the backgrounds separately and use it in your other Activity when you actually pass on there.

Post a Comment for "Change Background Image On User's Choice"