How To Show and hide ActionBar with AppCompat v.7

前端 未结 9 1600
忘了有多久
忘了有多久 2020-11-27 16:06

I have a simple app that displays text.

The app starts with a main screen with a few options (ex. an info button that leads to info about the app, a browse button th

相关标签:
9条回答
  • 2020-11-27 16:41

    In the activities where you want to have no action bar use a theme derived from Theme.AppCompat.NoActionBar or Theme.AppCompat.Light.NoActionBar. This activity will never be able to show the action bar unless you supply your own via setSupportActionBar(Toolbar).

    In the activities where you want to have the action bar use a theme derived from Theme.AppCompat, Theme.AppCompat.Light or Theme.AppCompat.Light.DarkActionBar. This will allow you to dynamically hide or show the action bar in such activity. You will not be able to supply your own action bar using these themes.

    When working with appcompat-v7 action bar you need to obtain it by calling getSupportActionBar() instead of getActionBar().

    0 讨论(0)
  • 2020-11-27 16:43

    You can hide and show the ActionBar programatically.

    To hide

    getSupportActionBar().hide();
    

    To Show

    getSupportActionBar().show();
    

    It can also be done from Fragments

    To hide

    getActivity().getSupportActionBar().hide();
    

    To Show

    getActivity().getSupportActionBar().show();
    

    Edit:

    As noted by @RenniePet,

    You need to call ((AppCompatActivity)getActivity()).getSupportActionBar(), if you're using Toolbar as the ActionBar.

    0 讨论(0)
  • 2020-11-27 16:45

    I hope this can be solution. It worked on my system:

    android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
    
    0 讨论(0)
提交回复
热议问题