Damirchi Damirchi - 1 year ago 70
Android Question

Change fragment background on create view dynamically

I want to change fragment background on load dynamically, Below code do that for me, But I have an issue on run-time and that is background changes happen after showing the fragment with default background.

for example when I want to swipe to load another fragment, On transition fragment appears with default background setting and after loading fragment and waiting a little moment that codes work at first time load.

I want to know where I'm wrong

public void setUserVisibleHint(boolean visible){
View view=RegisterFragment.this.getView();
if (view!=null)
RelativeLayout layout= (RelativeLayout) view.findViewById(R.id.back_layout);
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view= inflater.inflate(R.layout.fragment_register, container, false);
return view;

Jai Jai
Answer Source

You could override below method which will help you to update UI run-time while loading fragment:

    public void setMenuVisibility(boolean menuVisible) {


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download