Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to hide action bar in a specific fragment

I have Fragment A , B , C , D . I Want to hide action bar in fragment D .

I have tried getActivity().getActionBar().hide(); and it did not work.

public class Profile extends Fragment {

    public Profile() {
        // Required empty public constructor
    }

    public static Profile newInstance(int instance) {
        Bundle args = new Bundle();
        args.putInt("argsInstance", instance);
        Profile profile = new Profile();
        profile.setArguments(args);
        return profile;
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {

        getActivity().getActionBar().hide();


        // Inflate the layout for this fragment
        View profile = inflater.inflate(R.layout.fragment_profile, container, false);

        return profile;


    }

}
like image 411
Waseem Ha Avatar asked Dec 16 '16 23:12

Waseem Ha


People also ask

How do we hide the menu on the toolbar in one fragment?

When you click the show button to open a fragment, you can see the fragment menu items ordered before activity menu items. This is because of the menu item's android:orderInCategory attribute value. When you click the hide button to hide the fragment. The fragment menu items disappear from the action bar also.

How do I hide action bars?

If you want to hide Action Bar throughout the app (Activities, Fragments) everywhere, you can simply navigate to res > values > styles.

How can remove action bar for specific activity in Android?

If you want to hide Action Bar from the entire application (from all Activities and fragments), then you can use this method. Just go to res -> values -> styles. xml and change the base application to “Theme. AppCompat.


1 Answers

I had the same question and was searching for the answer. and got it!

Here it is. hope it will help:

// Hide the status bar.
int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN;
view.setSystemUiVisibility(uiOptions);
// Remember that you should never show the action bar if the
// status bar is hidden, so hide that too if necessary.
((AppCompatActivity)getActivity()).getSupportActionBar().hide();
like image 81
Asilbek Djamaldinov Avatar answered Sep 25 '22 22:09

Asilbek Djamaldinov