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;
}
}
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.
If you want to hide Action Bar throughout the app (Activities, Fragments) everywhere, you can simply navigate to res > values > styles.
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.
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();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With