Hide ActionBar in one fragment but show in another

2

I'm working on a project that's being done pretty much all based on fragments . So far, I have only activity and 4 fragments , within which I need only one of them does not have ActionBar . Common methods of hiding ActionBar did not work (% with%). How can I do this?

This is the fragment I do not want to have ActionBar:

package com.renanlazarotto.fserv.fragments;

        import android.os.Bundle;
        import android.support.v4.app.Fragment;
        import android.view.LayoutInflater;
        import android.view.View;
        import android.view.ViewGroup;
        import android.widget.Button;

        import com.renanlazarotto.fserv.activities.FservActivity;
        import com.renanlazarotto.fserv.R;

public class LoginFragment extends Fragment {
    public LoginFragment() {
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        ((FservActivity) getActivity()).getSupportActionBar().setTitle(R.string.titulo_login);

        View view = inflater.inflate(R.layout.fragment_login, container, false);

        Button logar = (Button) view.findViewById(R.id.login_button_entrar);

        logar.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                getActivity().getSupportFragmentManager().beginTransaction().replace(R.id.container, new ChamadosFragment()).commit();
            }
        });

        return view;
    }
}
    
asked by anonymous 26.11.2014 / 14:38

1 answer

2

After a bit of research, I realized that apparently it is not possible to hide ActionBar in only Fragment without affecting others. So I solved the problem as follows:

public static void mostrarActionBar(Activity parent) {
    ActionBarActivity abc = (ActionBarActivity) parent;
    abc.getSupportActionBar().show();
}
public static void esconderActionBar(Activity parent) {
    ActionBarActivity abc = (ActionBarActivity) parent;
    abc.getSupportActionBar().hide();
}

Where the parent parameter is passed as a reference of which Activity Fragment belongs (using the getActivity() method):

esconderActionBar(getActivity());
    
28.11.2014 / 16:59