Skip to content Skip to sidebar Skip to footer

How To Change The Background Of Activity In Fragment?

I want to change the background of activity in fragment. When I click the button in the Fragment , it choose the picture. And set the picture to the background of Activity. The fo

Solution 1:

relativeLayout is not initialized. Either is it not initialized or the initialization fails.

relativeLayout = (RelativeLayout)getActivity().findViewById(R.id.relativelayout);

in onActivityCreated of fragment class.

Or Initialize relativeLayout in Activity class. Use a interface as a callback to the activity and change the background in activity itself

Solution 2:

try something like this

declare RelativeLayout relativeLayout; in Activity

And in onCreate() of Activity

relativeLayout=(RelativeLayout)findViewById(R.id.relativelayout);

then in Fragment

getActiviy().relativeLayout.setBackground(background);

Post a Comment for "How To Change The Background Of Activity In Fragment?"